Tools
PowerShell Cheat Sheet — Commands for Windows Developers
PowerShell passes objects, not text, through its pipeline. These are the commands and patterns developers use most, with the Bash equivalents in mind.
Put it into practice with the matching tool.
Test a -match pattern →Advertisement
Navigation and files
Get-Location (pwd)Current directorySet-Location path (cd)Change directoryGet-ChildItem (ls, dir)List files; -Recurse for subfolders, -Force for hiddenGet-Content file (cat)Read a file; -Tail 20 -Wait to follow itSet-Content f -Value "x" -Encoding utf8Write a fileNew-Item -ItemType Directory -Force dirCreate a directory (like mkdir -p)Copy-Item / Move-Item / Remove-Itemcp / mv / rm (-Recurse for folders)Test-Path pathDoes a file or folder exist?Pipeline and objects
| Where-Object { $_.Length -gt 1MB }Filter objects (alias ?)| Select-Object Name, LengthPick properties; -First 5 like head| Sort-Object Length -DescendingSort by a property| ForEach-Object { $_.Name }Run code per item (alias %)| Measure-Object -LineCount lines (like wc -l)| Get-MemberShow an object's properties and methodsSelect-String "TODO" -Path *.tsSearch text in files (like grep)Variables and syntax
$name = "Ana"Assign a variable"Hello $name" / 'literal $name'Double quotes expand; single quotes do not$env:PATHRead an environment variable$env:NODE_ENV = "production"Set one for this session-eq -ne -gt -lt -like -matchComparison operatorscmd1; if ($?) { cmd2 }Run cmd2 only if cmd1 succeeded (&& in PowerShell 7)`Escape character and line continuationProcesses and system
Get-Process nodeList processes by name (ps)Stop-Process -Name nodeKill processes (kill)Get-NetTCPConnection -LocalPort 3000Find what is using a portInvoke-WebRequest url -OutFile fDownload a file (like curl -o)Invoke-RestMethod urlCall an API and parse JSON automatically(Get-Command node).SourceWhere a command lives (which)Data and help
Get-Content f.json | ConvertFrom-JsonParse JSON into objects$obj | ConvertTo-Json -Depth 5Serialise objects to JSONImport-Csv f.csv / Export-CsvRead and write CSV as objectsGet-Help cmd -ExamplesShow usage examplesSet-ExecutionPolicy -Scope CurrentUser RemoteSignedAllow local scripts to run