Introduction to PowerShellIvan SuhininSenior Software Engineer
What is PowerShell?Automation engineShell environmentScripting language
PowerShell as a shellA full replacement for CMDAt last something bash-like in WindowsJust… feel the power!
PowerShell as a languageVariables: $a, $nameArrays:  $arr = 1,2,3,4,5,6;   $sarr=1..6Hashes: $h = @{“Key1" = 23; “Key2" = 894}Functions: function hi ($name) { echo "Hi, $name!" }Classes:($o = New-Object Object) |Add-Member NoteProperty Name “Bianco"
PowerShell as an automation toolPredefined set of commands with lots of extensionsEasy batch operationsSimple command interconnections (pipelining)
Command typesCmdlets – Get-LocationFunctionsUser scripts - *.ps1Native applications (msbuild, csc)
CmdletsPredefined set of commandsForm: Verb-Noun:Get-LocationGet-ChildItemSet-LocationLong, descriptive names for scriptsAliases for daily usage
AliasesCreating short names for long cmdletsGet-Alias, Set-AliasMakes scripting more friendlyBy default has standard UNIX aliasesls, ps, pwd, date, kill, gal, pushd, popd
Wiring commands upPipelining: Get-Location | Get-MemberFunctional style.NET objects instead of strings (bash)Output becomes inputSelect – selecting only needed informationWhere – filtering resultsGroup – grouping resultsForEach – processing each input value
PowerShell providersAdapters to different subsystemsGet-PSProvider, Get-PSDriveDefault: WSMan, Alias, Environment, FileSystem, RegistryExtended: IIS, SQL, SharePoint, VMWare
Using external componentsWindows Management Instrumentation (WMI)gwmi win32_servicegwmi win32_operatingsystemCOM(New-Object -ComObjectWScript.Shell).Run("calc.exe")
Using .NETImporting assemblies:[Reflection.Assembly]::LoadWithPartialName("System.Messaging")Calling static methods:[System.Messaging.MessageQueue]::GetPrivateQueuesByMachine("localhost")Creating and using objects:$b = New-Object System.Text.StringBuilder$b.Append("Hello!")
manUltimate help systemExamplesDetailedFull
Demo: deleting MSMQ queues
Demo: sorting SQL tables by size
Demo: real-life deployment script
Development environmentAutocompletionTab keyWildcardsWorks for methodsPowerShell ISEPowerGUI
Q & A

Introduction To Power Shell