PowerShell Cheatsheet
PowerShell is an object-based shell and scripting language common on Windows and available cross-platform as PowerShell 7+.
Think in objects flowing through pipelines—not only text—and prefer approved verbs in cmdlet names.
Full lessons: PowerShell Tutorials
Basics
Get-Command / Get-Help
Discover cmdlets and read help.
Get-Command *process*
Get-Help Get-ChildItem -Examples
Verb-Noun
Cmdlets use approved verbs: Get, Set, New, Remove, etc.
Get-Process
Get-Service
Variables
Names start with $.
$name = "Ada"
Write-Output "Hi, $name"
Providers & paths
Navigate filesystems (and other providers) with familiar path cmdlets.
Set-Location C:\Projects
Get-ChildItem
Aliases
Shortcuts like ls, cd, gc exist—learn real cmdlet names for scripts.
Get-Alias ls
Pipeline & objects
Pipeline
Pass objects to the next cmdlet—not just strings.
Get-Process | Where-Object CPU -gt 10 | Select-Object Name, CPU
Where-Object
Filter objects. Script-block form is flexible.
Get-Service | Where-Object { $_.Status -eq 'Running' }
ForEach-Object
Run a block per object (% alias).
1..3 | ForEach-Object { $_ * 2 }
Select-Object
Pick properties or limit rows.
Get-ChildItem | Select-Object Name, Length -First 5
Files & JSON
Read / write text
Common file cmdlets for content.
Get-Content .\notes.txt
'Saved' | Set-Content .\out.txt
Copy / remove
File operations with clear cmdlets.
Copy-Item .\a.txt .\b.txt
Remove-Item .\temp.txt
ConvertFrom-Json
Parse JSON into objects.
$obj = Get-Content .\data.json -Raw | ConvertFrom-Json
ConvertTo-Json
Serialize objects for APIs or files.
$user | ConvertTo-Json -Depth 5
Scripts & errors
Parameters
Declare script or function parameters with types.
param(
[Parameter(Mandatory)]
[string]$Path
)
if / switch
Branching similar to other languages.
if (Test-Path $Path) {
Write-Output "exists"
}
try / catch
Handle terminating errors.
try {
Get-Content .\missing.txt -ErrorAction Stop
} catch {
Write-Error $_
}
Execution policy peek
Policy can block unsigned scripts on Windows—learn your environment's rules before changing them.
Get-ExecutionPolicy -List
Comments
One comment per signed-in account. Comments are saved with this page’s URL.