175 commands · 10 cheat sheets · Windows
PowerShell and Automation master quick reference
Browse 175 commands from 10 focused cheat sheets on page 1 of 1. Each example opens its matching detailed section.
PowerShell and Automation · 15 commands
PowerShell Background Jobs Cheat Sheet
| Use | Syntax | Examples |
|---|---|---|
| Start process job | $job = Start-Job -Name 'Inventory' -ScriptBlock { Get-Process |
Select-Object -First 5 } | View examples |
| Pass explicit arguments | Start-Job -ScriptBlock { param($Path) Get-Item `
-LiteralPath $Path } -ArgumentList `
'C:/Data/report.csv' | View examples |
| Start thread job | Start-ThreadJob -Name 'FastRead' -ScriptBlock { Get-Date `
} | View examples |
| List jobs | Get-Job |
Select-Object Id, Name, State, HasMoreData, Location | View examples |
| Inspect child jobs | $job.ChildJobs |
Select-Object Id, Name, State, Location, HasMoreData | View examples |
| Wait with timeout | Wait-Job -Job $job -Timeout 60 | View examples |
| Wait for any job | Wait-Job -Job $jobs -Any -Timeout 30 | View examples |
| Receive available output | Receive-Job -Job $job | View examples |
| Read output non-destructively | Receive-Job -Job $job -Keep | View examples |
| Wait and receive | Receive-Job -Job $job -Wait -AutoRemoveJob | View examples |
| Start remote job | $job = Invoke-Command -ComputerName `
'server01','server02' -ScriptBlock { Get-Date } -AsJob `
-ThrottleLimit 2 | View examples |
| Find failed child jobs | $job.ChildJobs |
Where-Object State -eq 'Failed' |
Format-List Location, JobStateInfo, Error | View examples |
| Stop a running job | Stop-Job -Job $job | View examples |
| Remove completed job | Remove-Job -Job $job | View examples |
| Remove finished jobs | Get-Job |
Where-Object State -in 'Completed','Failed','Stopped' |
Remove-Job | View examples |
PowerShell and Automation · 16 commands
PowerShell Classes and Custom Objects Cheat Sheet
| Use | Syntax | Examples |
|---|---|---|
| Create an ordered record | $Item = [pscustomobject][ordered]@{ Name = 'api'; State `
= 'Running' } | View examples |
| Add a semantic type name | $Item.PSObject.TypeNames.Insert(0, `
'Contoso.ServiceStatus') | View examples |
| Declare a class | class ServiceSpec { [string] $Name; [bool] $Enabled } | View examples |
| Invoke a constructor | $Spec = [ServiceSpec]::new('api', $true) | View examples |
| Declare an enum | enum HealthState { Unknown; Healthy; Degraded; Failed } | View examples |
| Validate a property value | [ValidateSet('Dev','Test','Prod')] [string] $Environment | View examples |
| Hide an implementation member | hidden [string] $CacheKey | View examples |
| Call a static method | [Widget]::NormalizeName(' API ') | View examples |
| Add a calculated property | $Item |
Add-Member -NotePropertyName Healthy -NotePropertyValue $true | View examples |
| Project calculated output | $Item |
Select-Object Name,@{n='Label';e={"$($_.Name):$($_.State)"}} | View examples |
| Accept typed pipeline input | param([Parameter(ValueFromPipeline)][ServiceSpec] `
$InputObject) | View examples |
| Document output type | [OutputType([ServiceSpec])] param() | View examples |
| Serialize with explicit depth | $Item | ConvertTo-Json -Depth 5 | View examples |
| Persist PowerShell data | $Item | Export-Clixml -LiteralPath '.\item.clixml' | View examples |
| Load module types at parse time | using module Contoso.Models | View examples |
| Set default display properties | Update-TypeData -TypeName Contoso.ServiceStatus `
-DefaultDisplayPropertySet Name,State -Force | View examples |
PowerShell and Automation · 16 commands
PowerShell Desired State Configuration Cheat Sheet
| Use | Syntax | Examples |
|---|---|---|
| Inspect standalone DSC | dsc --version | View examples |
| Inspect legacy module | Get-Module -ListAvailable PSDesiredStateConfiguration |
Select-Object Name,Version,Path | View examples |
| List DSC 3 resources | dsc resource list | View examples |
| Inspect resource schema | dsc resource schema --resource Microsoft.DSC.Debug/Echo | View examples |
| Read current state | dsc config get --file .\server.dsc.yaml | View examples |
| Test desired state | dsc config test --file .\server.dsc.yaml | View examples |
| Apply desired state | dsc config set --file .\server.dsc.yaml | View examples |
| Supply parameter data | dsc config --parameters-file .\prod.parameters.yaml set `
--file .\server.dsc.yaml | View examples |
| Inspect Windows LCM | Get-DscLocalConfigurationManager | View examples |
| Test legacy configuration | Test-DscConfiguration -Path .\Compiled -Detailed | View examples |
| Apply compiled MOF | Start-DscConfiguration -Path .\Compiled -Wait -Verbose | View examples |
| Read last LCM run | Get-DscConfigurationStatus -All | View examples |
| Parse a configuration script | $null = `
[System.Management.Automation.Language.Parser]::ParseFile('.\Config.ps1',[ref]$null,[ref]$null) | View examples |
| Recognize WhatIf boundary | Get-Command Start-DscConfiguration |
Select-Object -ExpandProperty Parameters | View examples |
| Export discoverable state | dsc config export --file .\resources.yaml | View examples |
| Read DSC operational events | Get-WinEvent -LogName `
'Microsoft-Windows-DSC/Operational' -MaxEvents 50 | View examples |
PowerShell and Automation · 17 commands
PowerShell Error Handling Cheat Sheet
| Use | Syntax | Examples |
|---|---|---|
| Write a non-terminating error | Write-Error 'The record is invalid' | View examples |
| Make a command error terminating | Get-Item -LiteralPath $Path -ErrorAction Stop | View examples |
| Hide a command error | Get-Item -LiteralPath $Path -ErrorAction `
SilentlyContinue | View examples |
| Catch a failure | catch { Write-Warning $_.Exception.Message } | View examples |
| Catch one exception type | catch [System.IO.FileNotFoundException] { Write-Warning `
'Missing file' } | View examples |
| Order specific handlers first | catch [System.UnauthorizedAccessException] { `
Write-Warning 'Access denied' } | View examples |
| Inspect the caught error | $_.Exception.Message | View examples |
| Inspect the category | $_.CategoryInfo.Category | View examples |
| Read the newest error | $Error[0] | View examples |
| Capture command errors | Get-Item missing.txt -ErrorVariable lookupErrors `
-ErrorAction SilentlyContinue | View examples |
| Always run cleanup | finally { $stream.Dispose() } | View examples |
| Raise a terminating error | throw 'Configuration is invalid' | View examples |
| Re-throw the current error | throw | View examples |
| Set a scoped default action | $ErrorActionPreference = 'Stop' | View examples |
| Write a warning | Write-Warning 'Using fallback configuration' | View examples |
| Read a native exit code | if ($LASTEXITCODE -ne 0) { throw `
"Tool failed: $LASTEXITCODE" } | View examples |
| Inspect command success | if (-not $?) { Write-Warning 'The last operation failed' `
} | View examples |
PowerShell and Automation · 20 commands
PowerShell Files and Directories Cheat Sheet
| Use | Syntax | Examples |
|---|---|---|
| Show the current location | Get-Location | View examples |
| List directory contents | Get-ChildItem -LiteralPath . -Force | View examples |
| Change directory | Set-Location -LiteralPath 'C:\Projects' | View examples |
| Move to the parent | Set-Location .. | View examples |
| Resolve an existing path | Resolve-Path -LiteralPath '.\config.json' | View examples |
| Create a directory | New-Item -ItemType Directory -Path '.\reports' | View examples |
| Create a text file | New-Item -ItemType File -Path '.\notes.txt' -Value `
'First line' | View examples |
| Check whether a path exists | Test-Path -LiteralPath '.\notes.txt' -PathType Leaf | View examples |
| Inspect one item | Get-Item -LiteralPath '.\notes.txt' | View examples |
| Read a text file | Get-Content -LiteralPath '.\notes.txt' | View examples |
| Read the last lines | Get-Content -LiteralPath '.\app.log' -Tail 20 | View examples |
| Follow a growing log | Get-Content -LiteralPath '.\app.log' -Tail 20 -Wait | View examples |
| Copy a file | Copy-Item -LiteralPath '.\config.json' -Destination `
'.\config.backup.json' | View examples |
| Copy a directory tree | Copy-Item -LiteralPath '.\reports' -Destination `
'.\reports-backup' -Recurse | View examples |
| Move or rename an item | Move-Item -LiteralPath '.\draft.txt' -Destination `
'.\final.txt' | View examples |
| Find files recursively | Get-ChildItem -Path . -Filter '*.json' -File -Recurse | View examples |
| Filter files by size | Get-ChildItem -Path . -File -Recurse |
Where-Object Length -GT 10MB | View examples |
| Search inside files | Select-String -Path '.\*.log' -Pattern 'error' `
-CaseSensitive:$false | View examples |
| Preview file removal | Remove-Item -LiteralPath '.\obsolete.txt' -WhatIf | View examples |
| Preview recursive removal | Remove-Item -LiteralPath '.\build-output' -Recurse `
-WhatIf | View examples |
PowerShell and Automation · 16 commands
PowerShell Modules and Repositories Cheat Sheet
| Use | Syntax | Examples |
|---|---|---|
| List available module versions | Get-Module -ListAvailable Pester |
Sort-Object Version -Descending | View examples |
| List loaded modules | Get-Module | Sort-Object Name, Version | View examples |
| Inspect module search paths | $env:PSModulePath -split [IO.Path]::PathSeparator | View examples |
| List repositories | Get-PSResourceRepository | Sort-Object Priority, Name | View examples |
| Find exact resource | Find-PSResource -Name Pester -Version 5.6.1 -Repository `
PSGallery | View examples |
| List available versions | Find-PSResource -Name Pester -Version '*' -Repository PSGallery |
Sort-Object Version -Descending | View examples |
| Stage a module package | Save-PSResource -Name Pester -Version 5.6.1 -Repository `
PSGallery -Path './staging' | View examples |
| Validate a manifest | Test-ModuleManifest -Path `
'./staging/Pester/5.6.1/Pester.psd1' | View examples |
| Inspect script signatures | Get-ChildItem './staging/Pester' -Recurse -File -Include '*.ps1','*.psm1' |
Get-AuthenticodeSignature | View examples |
| Preview current-user install | Install-PSResource -Name Pester -Version 5.6.1 `
-Repository PSGallery -Scope CurrentUser -WhatIf | View examples |
| List installed resources | Get-InstalledPSResource -Name Pester |
Sort-Object Version -Descending | View examples |
| Preview module update | Update-PSResource -Name Pester -WhatIf | View examples |
| Import a pinned version | Import-Module -FullyQualifiedName @{ ModuleName = `
'Pester'; RequiredVersion = '5.6.1' } -ErrorAction `
Stop | View examples |
| Inspect exported commands | Get-Command -Module Pester | Sort-Object Name | View examples |
| Unload from session | Remove-Module -Name Pester -Force | View examples |
| Preview uninstall | Uninstall-PSResource -Name Pester -Version 5.6.1 -Scope `
CurrentUser -WhatIf | View examples |
PowerShell and Automation · 17 commands
PowerShell Pipelines Cheat Sheet
| Use | Syntax | Examples |
|---|---|---|
| Inspect object members | Get-Process | Get-Member | View examples |
| Inspect one object | Get-Process | Select-Object -First 1 | Format-List * | View examples |
| Filter by one property | Get-Process | Where-Object CPU -gt 10 | View examples |
| Filter with a script block | Get-Service |
Where-Object { $_.Status -eq 'Running' -and $_.CanStop } | View examples |
| Select properties | Get-Process | Select-Object Name, Id | View examples |
| Take the first objects | Get-Process | Select-Object -First 5 | View examples |
| Expand one property | Get-Process | Select-Object -ExpandProperty Name | View examples |
| Calculate a property | Get-Process |
Select-Object Name, @{Name='MemoryMB'; Expression={[math]::Round($_.WorkingSet64 / 1MB, 1)}} | View examples |
| Sort descending | Get-Process | Sort-Object WorkingSet64 -Descending | View examples |
| Transform each object | Get-Process |
ForEach-Object { $_.Name.ToUpperInvariant() } | View examples |
| Group by a property | Get-Service | Group-Object Status | View examples |
| Measure numeric values | Get-ChildItem -File |
Measure-Object Length -Sum -Average | View examples |
| Save and continue | Get-Process |
Tee-Object -Variable processes |
Sort-Object CPU -Descending | View examples |
| Export objects to CSV | Get-Process |
Select-Object Name, Id, CPU |
Export-Csv processes.csv -NoTypeInformation | View examples |
| Import CSV objects | Import-Csv processes.csv | View examples |
| Format a final table | Get-Process |
Sort-Object CPU -Descending |
Format-Table Name, Id, CPU -AutoSize | View examples |
| Run an action per object | Get-ChildItem *.log |
ForEach-Object { Compress-Archive -LiteralPath $_.FullName -DestinationPath ($_.FullName + '.zip') } | View examples |
PowerShell and Automation · 18 commands
PowerShell Registry Cheat Sheet
| Use | Syntax | Examples |
|---|---|---|
| List registry drives | Get-PSDrive -PSProvider Registry | View examples |
| Use a full hive path | Get-Item -LiteralPath `
'Registry::HKEY_CURRENT_USER\Software' | View examples |
| List immediate subkeys | Get-ChildItem -LiteralPath 'HKCU:\Software' | View examples |
| Find descendant keys | Get-ChildItem -LiteralPath 'HKCU:\Software\Acme' `
-Recurse | View examples |
| Test a key path | Test-Path -LiteralPath 'HKCU:\Software\Acme' | View examples |
| Inspect a key object | Get-Item -LiteralPath 'HKCU:\Software\Acme' | View examples |
| Read key values | Get-ItemProperty -LiteralPath 'HKCU:\Software\Acme' | View examples |
| Read one raw value | Get-ItemPropertyValue -LiteralPath 'HKCU:\Software\Acme' `
-Name 'Theme' | View examples |
| Preview key creation | New-Item -Path 'HKCU:\Software\Acme' -WhatIf | View examples |
| Preview a string value | New-ItemProperty -LiteralPath 'HKCU:\Software\Acme' `
-Name 'Theme' -Value 'Dark' -PropertyType String `
-WhatIf | View examples |
| Preview a DWORD value | New-ItemProperty -LiteralPath 'HKCU:\Software\Acme' `
-Name 'PageSize' -Value 25 -PropertyType DWord -WhatIf | View examples |
| Preview changing a value | Set-ItemProperty -LiteralPath 'HKCU:\Software\Acme' `
-Name 'Theme' -Value 'Light' -WhatIf | View examples |
| Preview renaming a value | Rename-ItemProperty -LiteralPath 'HKCU:\Software\Acme' `
-Name 'Theme' -NewName 'ColorTheme' -WhatIf | View examples |
| Preview clearing data | Clear-ItemProperty -LiteralPath 'HKCU:\Software\Acme' `
-Name 'Theme' -WhatIf | View examples |
| Preview removing a value | Remove-ItemProperty -LiteralPath 'HKCU:\Software\Acme' `
-Name 'Theme' -WhatIf | View examples |
| Preview removing a key | Remove-Item -LiteralPath 'HKCU:\Software\Acme' -Recurse `
-WhatIf | View examples |
| Export a key tree | reg.exe export 'HKCU\Software\Acme' '.\Acme-backup.reg' `
/y | View examples |
| Capture selected state | Get-ItemProperty -LiteralPath 'HKCU:\Software\Acme' |
Select-Object Theme, PageSize | View examples |
PowerShell and Automation · 24 commands
PowerShell REST APIs and Web Requests Cheat Sheet
| Use | Syntax | Examples |
|---|---|---|
| Deserialize an API response | Invoke-RestMethod -Uri $Uri -Method Get | View examples |
| Inspect an HTTP response | $Response = Invoke-WebRequest -Uri $Uri -Method Get | View examples |
| Encode GET query values | Invoke-RestMethod -Uri $Uri -Method Get -Body @{ q = `
'blue widget'; page = 2 } | View examples |
| Serialize JSON deliberately | $Json = @{ name = 'widget'; enabled = $true } |
ConvertTo-Json -Depth 10 -Compress | View examples |
| Post UTF-8 JSON | Invoke-RestMethod -Uri $Uri -Method Post -Body $Json `
-ContentType 'application/json; charset=utf-8' | View examples |
| Request a response media type | Invoke-RestMethod -Uri $Uri -Headers @{ Accept = `
'application/json' } | View examples |
| Prompt for a bearer token | Invoke-RestMethod -Uri $Uri -Authentication Bearer `
-Token (Read-Host -AsSecureString) | View examples |
| Capture a web session | Invoke-WebRequest -Uri $Uri -SessionVariable ApiSession | View examples |
| Reuse cookies and session state | Invoke-RestMethod -Uri $Uri -WebSession $ApiSession | View examples |
| Use a client certificate | Invoke-RestMethod -Uri $Uri -Certificate (Get-Item `
"Cert:\CurrentUser\My\$Thumbprint") | View examples |
| Constrain the TLS protocol | Invoke-RestMethod -Uri $Uri -SslProtocol Tls12 | View examples |
| Use an explicit proxy | Invoke-RestMethod -Uri $Uri -Proxy `
'https://proxy.example.com:8443' | View examples |
| Follow bounded relation links | Invoke-RestMethod -Uri $Uri -FollowRelLink `
-MaximumFollowRelLink 5 | View examples |
| Capture status and headers | Invoke-RestMethod -Uri $Uri -StatusCodeVariable Status `
-ResponseHeadersVariable Headers | View examples |
| Retry a bounded request | Invoke-RestMethod -Uri $Uri -MaximumRetryCount 3 `
-RetryIntervalSec 2 | View examples |
| Bound connection and idle reads | Invoke-RestMethod -Uri $Uri -ConnectionTimeoutSeconds 10 `
-OperationTimeoutSeconds 30 | View examples |
| Cancel a request job | Stop-Job -Job $RequestJob | View examples |
| Download to an exact path | Invoke-WebRequest -Uri $Uri -OutFile '.\artifact.zip' | View examples |
| Resume a partial download | Invoke-WebRequest -Uri $Uri -OutFile `
'.\artifact.zip.part' -Resume | View examples |
| Calculate a SHA-256 digest | (Get-FileHash -LiteralPath '.\artifact.zip' -Algorithm `
SHA256).Hash | View examples |
| Process HTTP error bodies | Invoke-RestMethod -Uri $Uri -SkipHttpErrorCheck `
-StatusCodeVariable Status | View examples |
| Catch request failures | try { Invoke-RestMethod -Uri $Uri -ErrorAction Stop } `
catch { Write-Error $_ } | View examples |
| Use safe Windows PowerShell parsing | Invoke-WebRequest -UseBasicParsing -Uri $Uri | View examples |
| Invoke native curl explicitly | curl.exe --fail --output artifact.zip `
https://example.com/artifact.zip | View examples |
PowerShell and Automation · 16 commands
Windows Scheduled Tasks PowerShell Cheat Sheet
| Use | Syntax | Examples |
|---|---|---|
| List tasks | Get-ScheduledTask | Sort-Object TaskPath, TaskName | View examples |
| Get one exact task | Get-ScheduledTask -TaskPath `
'\CmdMemo\' -TaskName 'NightlyExport' | View examples |
| Inspect runtime information | Get-ScheduledTaskInfo -TaskPath `
'\CmdMemo\' -TaskName 'NightlyExport' | View examples |
| Create an action | $action = New-ScheduledTaskAction -Execute 'pwsh.exe' `
-Argument '-NoProfile -File C:\Scripts\Export.ps1' | View examples |
| Create a daily trigger | $trigger = New-ScheduledTaskTrigger -Daily -At '02:00' | View examples |
| Create a startup trigger | $trigger = New-ScheduledTaskTrigger -AtStartup | View examples |
| Run as a service account | $principal = New-ScheduledTaskPrincipal -UserId `
'NT AUTHORITY\SYSTEM' -LogonType ServiceAccount `
-RunLevel Highest | View examples |
| Set operational behavior | $settings = New-ScheduledTaskSettingsSet `
-ExecutionTimeLimit (New-TimeSpan -Hours 1) `
-StartWhenAvailable | View examples |
| Compose a task object | $task = New-ScheduledTask -Action $action -Trigger `
$trigger -Settings $settings -Description `
'Nightly export' | View examples |
| Register a task | Register-ScheduledTask -TaskPath `
'\CmdMemo\' -TaskName 'NightlyExport' -InputObject $task | View examples |
| Start on demand | Start-ScheduledTask -TaskPath `
'\CmdMemo\' -TaskName 'NightlyExport' | View examples |
| Stop a running task | Stop-ScheduledTask -TaskPath `
'\CmdMemo\' -TaskName 'NightlyExport' | View examples |
| Disable triggers | Disable-ScheduledTask -TaskPath `
'\CmdMemo\' -TaskName 'NightlyExport' | View examples |
| Enable a task | Enable-ScheduledTask -TaskPath `
'\CmdMemo\' -TaskName 'NightlyExport' | View examples |
| Export task XML | Export-ScheduledTask -TaskPath `
'\CmdMemo\' -TaskName 'NightlyExport' | Set-Content -LiteralPath '.\NightlyExport.xml' -Encoding Unicode | View examples |
| Remove with confirmation | Unregister-ScheduledTask -TaskPath `
'\CmdMemo\' -TaskName 'NightlyExport' -Confirm | View examples |



