PowerShell Cheat Sheet

Searchable reference for everyday PowerShell cmdlets.

CmdletDescription
Get-ChildItemList items (alias: ls, dir)
Get-ChildItem -Recurse -Filter *.csRecursive file search
Get-ChildItem -ForceInclude hidden items
Set-LocationChange directory (alias: cd)
Get-LocationPrint working directory (alias: pwd)
Push-Location ; Pop-LocationSave and restore location
Resolve-Path .\fExpand to absolute path
Get-Item <path> | Format-List *All metadata for an item
New-Item -Type Directory pCreate folder
New-Item -ItemType File fCreate empty file
Remove-Item -Recurse -Force pRecursive delete
Copy-Item -Recurse a bCopy folder
Move-Item a bMove / rename
Rename-Item old newRename in place
New-Item -ItemType SymbolicLink -Path link -Target tgtSymbolic link
Get-Content <file>Read file (alias: cat)
Get-Content f -Tail 20 -WaitFollow file (like tail -f)
Get-Content f -TotalCount 20First 20 lines
Set-Content -Path f -Value 'x'Write string to file
Add-Content -Path f -Value 'x'Append to file
Out-File -FilePath f -Encoding utf8Write file as UTF-8
Select-String 'pat' fGrep equivalent
Select-String -Pattern 'pat' -Path *.cs -CaseSensitiveCase-sensitive search
(Get-Content f) -replace 'foo','bar' | Set-Content fIn-place replace
ForEach-Object { ... }Pipeline loop
Where-Object { $_.Foo -eq 1 }Pipeline filter
? Name -like '*x*'Where-Object short syntax
Select-Object -First 5Take first N
Select-Object -Property Name,SizeProject properties
Sort-Object Foo -DescendingSort by property
Group-Object FooGroup by property
Measure-Object -LineCount lines
Measure-Object Size -Sum -AverageNumeric aggregates
Get-Process | ? Name -like '*app*'Find process
Stop-Process -Id 1234 -ForceKill process
Stop-Process -Name app -ForceKill all by name
Start-Process -Verb RunAsRun elevated
Start-Process -FilePath app.exe -ArgumentList 'a','b'Launch with args
Get-Service | ? Status -eq 'Running'Running services
Restart-Service -Name svcRestart Windows service
$env:VAR = 'value'Set env var (session)
[Environment]::SetEnvironmentVariable('VAR','v','User')Persist user env var
Get-ChildItem env: | Sort NameList all env vars
Remove-Item env:VARUnset env var
Get-PSDriveList filesystem-like drives
Get-VolumeShow volume sizes
Get-ComputerInfo | Select OsName,OsVersionOS info
Get-DateCurrent date / time
(Get-Date) - (Get-Date '2025-01-01')Time span between dates
Compress-Archive a -DestinationPath a.zipMake zip
Expand-Archive a.zip -DestinationPath .Extract zip
Invoke-WebRequest -Uri urlHTTP fetch (alias: curl)
Invoke-WebRequest -Uri url -OutFile fDownload to file
Invoke-RestMethod -Uri urlAuto-parse JSON response
Test-NetConnection host -Port 443TCP port check
Resolve-DnsName example.comDNS lookup
ConvertFrom-JsonParse JSON string
ConvertTo-Json -Depth 10Serialise to JSON, deep
Import-Csv f.csvParse CSV to objects
Export-Csv f.csv -NoTypeInformationWrite objects to CSV
ConvertFrom-StringDataParse key=value text
Test-Path <path>Does it exist?
Split-Path -Leaf <path>Get filename portion
Join-Path a b cCombine path segments
Get-Command <name>Find a command
Get-Help <cmd>Show help
Get-Help <cmd> -ExamplesJust the examples block
Get-MemberInspect object members
Get-AliasList aliases
Get-HistoryCommand history
Set-ExecutionPolicy -Scope CurrentUser RemoteSignedAllow signed remote scripts
$ErrorActionPreference = 'Stop'Make errors terminating
try { ... } catch { ... } finally { ... }Structured exception handling

About this tool

Verb-Noun cmdlets for file system, process, pipeline, archives and HTTP — with one-line descriptions and common aliases.

An unhandled error has occurred. Reload ×