PowerShell Cheat Sheet Import, Export, Common cmdlets CommonCommon Aliases Aliases Export-CliXML Import-CliXML , chdir, sl Set-Location gcm Get- ConvertTo-XML ConvertTo-HTML cat, gc, Get-Content foreach,% Foreach-Object Export-CSV Import-CSV ac Add-Content sort Sort-Object ConvertTo-CSV ConvertFrom-CSV sc Set-Content where, ? Where-Object Basic Commands , cp, cpi Copy-Item diff, compare Compare-Object , ls, gci Get-ChildItem Cmdlet Commands built into shell written in . , erase, rd, ri, rm, Remove-Item Flow Control gi Get-Item Functions Commands written in PowerShell language mi, , mv Move-Item copy, cp, cpi Copy-Item Parameter Argument to a Cmdlet/Function/Script If(){} Elseif(){ } Else{ } si Set-Item move, mv, mi Move-Item Alias Shortcut for a Cmdlet or Function while(){} ni New-Item del, rm Remove-Item Scripts Text files with .ps1 extension For($i=0; $i -lt 10; $i++){} -Sleep rni, Rename-Item Applications Existing windows programs Foreach($file in dir :\){$file.name} sajb Start-Job fFt -Table Pipelines Pass objects Get-process word | Stop-Process 1..10 | foreach{$_} compare, diff Compare-Object fl Format-List Ctrl+c Interrupt current command group Group-Object gcim Get-CimInstance Left/right Navigate editing cursor curl, iwr, Invoke-WebRequest cat, gc, type Get-Content Ctrl+left/right Navigate a word a Comments, Escape Characters measure Measure-Object nal New-Alias sc Set-Content Home / End End Move to start / end of line #Comment Comment rvpa Resolve-Path h, history, ghy Get-History Up/down Move up and down through history <#comment#> Multiline Comment rujb Resume-Job ihy, r Invoke-History Insert Toggles between insert/overwrite mode "`"test`"" Escape char ` set, sv Set-Variable gp Get-ItemProperty F7 Command history in a window `t Tab shcm Show-Command sp Set-ItemProperty Tab / Shift-Tab Command line completion `n New line sort Sort-Object pwd, gl Get-Location ` Line continue sasv Start-Service gm Get-Member Variables saps, start Start-Process sls Select-String Parameters sujb Suspend-Job cd, chdir, sl Set-Location $var = "string" Assign variable wjb Wait-Job , clear Clear-Host $a,$b = 0 or $a,$b = 'a','b' Assign multiple variables -Confirm Prompt whether to take action ?, where Where-Object $a,$b = $b,$a Flip variables -WhatIf Displays what command would do , write Write-Output Arrays Objects $var=[int]5 Strongly typed variable Assignment, Logical, Comparison $arr = "a", "b" Array of strings $arr = @() Empty array =, +=, -=, ++,-- Assign values to variable $arr[5] Sixth array element Get-Command Get all commands -and, -or, -not,! Connect expressions / statements $arr[-3..-1] Last three array elements Get-Command -Module RGHS Get all commands in RGHS module -eq, -ne Equal, not equal $arr[1,4+6..9] Elements at index 1,4, 6-9 Get-Command Get-p* Get all commands starting with get-p -gt, -ge Greater than, greater than or equal $arr[1] += 200 Add to array item value Get-help get-process Get help for command -lt, -le Less than, less than or equal $z = $arA + $arB Two arrays into single array Get-Process | Get-Member Get members of the object - “Hi” -replace “H”, “P” [pscustomobject]@{x=1;z=2} Create custom object Get-Process| format-list -properties * Get-Process as list with all properties -match, -notmatch Regular expression match (Get-Date).Date Date property of object -like, -notlike Wildcard matching -contains, -notcontains Check if value in array Scripts -in, -notin Reverse of contains, notcontains. Writing output and reading Set-ExecutionPolicy -ExecutionPolicy Bypass Set execution policy to allow all scripts "This displays a string" String is written directly to output ."\\c-is-ts-91\c$\scripts\script.ps1” Run Script.PS1 script in current scope Write-Host "color" -ForegroundColor Red -NoNewLine String with colors, no new line at end &"\\c-is-ts-91\c$\scripts\script.ps1" Run Script.PS1 script in script scope $age = Read-host "Please enter your age" Set $age variable to input from user .\Script.ps1 Run Script.ps1 script in script scope $pwd = Read-host "Please enter your password" -asSecureString Read in $pwd as secure string $profile Your personal profile that runs at launch Clear-Host Clear console