310 likes | 456 Views
Windows PowerShell Introduction. Morgan Simonsen morgan.simonsen@ementor.no Ementor. 1. What Will We Cover?. What is Windows PowerShell? How does Windows PowerShell work? How can I use Windows PowerShell?. 2. Helpful Experience. Command line experience; cmd.exe, BASH etc.
E N D
Windows PowerShell Introduction Morgan Simonsen morgan.simonsen@ementor.no Ementor 1
What Will We Cover? • What is Windows PowerShell? • How does Windows PowerShell work? • How can I use Windows PowerShell? 2
Helpful Experience • Command line experience; cmd.exe, BASH etc. • Command line experience; parameters, output etc. • Scripting experience (PERL, VBScript, JScript) etc.) Level 200 3
Microsoft Products Providing Windows PowerShell Cmdlets Windows Server “Longhorn” Windows Vista Exchange Server 2007 Operations Manager 2007 Virtual Machine Manager Data Protection Manager “V2” 4
Why PowerShell? • As companiesscale-out; managementbecomesvery hard • Currenttechnologies; VBScript, WMI, RDP • PowerShell willprovide a unifiedmanagementexperience 5
Admin Development Model • Try things out in an interactive shell • Stitch things together with utilities • Put the results in a script file • Realize that the tools are unsuitable and restart with a new set of tools • Generalize (e.g., parameterize) • Clean it up production-quality • Integrate into your environment • Share with the community 7
Introducing Windows PowerShell • New Windows command-lineshelldesigned for system administrators • Interactive prompt and scripting environment • Builton .NET CommonLanguageRuntime (CLR) and .NET Framework 8
PowerShell Design Goals • Easeofuse • Consisencyofsyntax • Easeoflearningcurve 9
How is PowerShell different? • PS processesobjects, not text • Large set (>100) ofbuilt in commandswithcosistentinterface • Commoncommand parser • Can run all existingutilities, tools • Multiple commandswithoutbatch files (;) 10
Getting and installing PowerShell • Microsoft Downloadsite • x86/x64 versionsavailable • Installationrequirements: • Windows XP SP2, Windows Server 2003 SP1 or later versionsof Windows • .NET Framework 2.0 11
Getting and installing PowerShell Continued • WinXP, W2K3 Srv: Update.exeinstall • Vista/W2K8 Srv: .msu (componentbasedinstall) • Install locations: • X86: • %systemroot%\system32\WindowsPowerShell\V1.0 • X64: • %systemroot%\system32\WindowsPowerShell\V1.0 • %systemroot%\Syswow64\WindowsPowerShell\V1.0 12
Starting PowerShell • Powershell.exe <parameters> • powershell-psconsolefile sqlsnapin.psc1 • powershell-version 1.0 -nologo -inputformat text -outputformat XML • powershell-command {get-eventlog-lognamesecurity} • powershell-command "& {get-eventlog-lognamesecurity}” • Start Menu 13
Cmdlets (Command-lets) • Built-in, single-featurecommandsthatmanipulateobjects in PS • Small and simple, designed to be used togetherwithother cmdlets (pipelining) • Comeswithbuilt-inhelp (Get-Help) • Use a Verb-Nounnames (Get-Service, Set-Service) 14
Cmdlets (Command-lets) Structure Name Alias Server StorageQuota ---- ---- ------ ------------ Bob Kelly bobk smbex01 unlimited Kim Akers kima smbex01 unlimited Property Names Property Values Name Argument String Verb Noun MSH> get-mailbox –server “smbex01” Command Parameter 15
Cmdlet parameters • Alwaysidentified by -, never /, -- or \ • Supports concatenation:get-help <command> -det • Namescan be omitted:get-help –nameget-alias = get-helpget-alias 16
Gettinghelp in PS • Get-Helpcmdlet • Get-Help <cmdlet>eg. Get-HelpGet-Commandeg. Get-HelpGet-Command –detailedeg. Get-HelpGet-Command –fulleg. Get-HelpGet-Command-examples • Get-Helpabout_signing 17
Getting help: The 4 Pillars of Discoverability Get-Command Get-Help and -? Get-PSDrive Get-Members 18
ProcessingObjects • PS workswith .NET Objects • .NET Objectscontain: • Data • Properties • Methods 19
Learningaboutobjects • Get-Member: displays informationabout .NET objects a cmdletreturnsget-service | get-member 20
Formatting Output • PS cmdlets never format data • Format cmdlets format data • Format-List • Format-Table • Format-Custom • Format-Wide • Everycmdlet has default formatting basedonthe format cmdlets, whichyoucan override 21
Aliases • PS has severalaliases by default (dir, ls, cls, del etc) • Display aliases:get-alias • Create alias:set-aliasghGet-Help • Delete alias:remove-itemalias:gh 22
Someuseful cmdlets • Get-Command • Get-Childitem • Get-ChildItemProperty • Get-Service • Get-WMIObject • Invoke-Item 23
Using Windows Programs • PS can run all Windows programs • Must be in pathstatement($env:path) • List:Get-Command *.exe • Aliases do not support itsnamesake’sparamteres 24
Tab Completion • PS support Tab completions for: • Cmdletnames • Registrypaths • Filesystem paths • Certificatepaths 25
Pipelining • Cmdlets can be ”piped” together to form complexcommands • Output from onecmdletmovealongthe pipe to anothercmdlet • PS pipeline operator is | (pipe) 26
For More Information • Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShell • Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx 27