PowerShell Cheat Sheet
A reference for PowerShell 7 and Windows PowerShell 5.1, discovering cmdlets, the object pipeline, filtering and formatting, managing files, processes and services, plus variables and flow control.
A reference for PowerShell (PowerShell 7 on Windows, macOS, and Linux, and Windows
PowerShell 5.1). Rows marked Windows only don't work on macOS or Linux. Commands are cmdlets in
Verb-Noun form (e.g. Get-Process) and most accept objects through
the pipe. Run Get-Help CMDLET -Examples for examples.
Discovering commands
| Cmdlet | What it does |
|---|---|
Get-Command *service* | Find commands by name |
Get-Help CMDLET | Show help for a cmdlet |
Get-Member | List an object's properties & methods |
Get-Alias | List shortcut aliases (e.g. cd, gci) |
Files & navigation
| Cmdlet | What it does |
|---|---|
Get-ChildItem | List items (alias dir/gci; ls on Windows only) |
Set-Location PATH | Change directory (alias cd) |
Get-Content FILE | Read a file (alias gc/type; cat on Windows only) |
Set-Content FILE "text" | Write text to a file (replaces existing content) |
Copy-Item SRC DEST -Recurse | Copy files or folders |
Remove-Item PATH -Recurse -Force | Delete items (careful) |
Test-Path PATH | Check if a path exists |
The pipeline & filtering
| Cmdlet | What it does |
|---|---|
Where-Object { $_.CPU -gt 10 } | Filter objects by a condition |
Select-Object Name, Id | Pick specific properties |
Sort-Object CPU -Descending | Sort objects |
Measure-Object -Sum | Count / sum / average values |
ForEach-Object { $_ * 2 } | Run a block for each item |
Get-Process | Format-Table -AutoSize | Display results as a table |
System & processes
| Cmdlet | What it does |
|---|---|
Get-Process | List running processes |
Stop-Process -Name app -Force | Kill a process |
Get-Service | List services (Windows only) |
Start-Service -Name w32time | Start a service (Stop-Service to stop; Windows only) |
Get-ComputerInfo | OS and hardware details (Windows only) |
Variables & flow
| Syntax | What it does |
|---|---|
$x = 5 | Assign a variable |
$items = @(1,2,3) | Create an array |
if ($x -gt 3) { "big" } | Conditional (-eq -ne -lt -gt -like) |
foreach ($i in $items) { $i } | Loop over a collection |
Invoke-WebRequest URL | Download / call a URL (alias iwr) |
Run scripts with .\script.ps1. If blocked, set the policy
for your session: Set-ExecutionPolicy -Scope Process RemoteSigned (Windows only; on macOS and
Linux the policy is Unrestricted and can't be changed). Use
Tab to complete cmdlet and parameter names.
What this does
A PowerShell cheat sheet covers discovering cmdlets, the object pipeline, filtering and formatting, managing files and services, and flow control.
How to use it
- Browse by section.
- Find the cmdlet you need.
- Copy it with one tap.
- Adapt the parameters.
Example
Get-Process | Sort-Object CPU -Descending lists the busiest processes.
Last updated .
Frequently asked questions
What is a cmdlet?
A cmdlet is a native PowerShell command named in Verb-Noun form, such as Get-Process or Set-Location. Most accept and emit objects, which is what makes the pipeline so powerful.
Why won’t my script run?
On Windows, the execution policy may be blocking it. For the current session, run Set-ExecutionPolicy -Scope Process RemoteSigned, then run your script. On macOS and Linux the policy is always Unrestricted, so look for another cause.
Do my old CMD commands still work?
Many familiar names do, because PowerShell defines aliases like dir, cd, copy, del, and type (plus ls and cat on Windows). They point to cmdlets, so old switches may not work. For full functionality, learn the underlying cmdlets they point to.
Related tools
Linux Command Cheat Sheet
The essential Linux terminal commands on one page, files and navigation, permissions, processes, networking, and package managers. A quick reference for the bash shell.
Windows CMD Cheat Sheet
A quick reference for the Windows Command Prompt, file and folder commands, networking, disk and system tools, plus handy keyboard shortcuts.
macOS Terminal Cheat Sheet
A reference for the macOS Terminal, the Mac-only commands (open, pbcopy, mdfind), system and defaults tools, Homebrew, core Unix commands, and keyboard shortcuts.
IBM AS/400 (IBM i) Cheat Sheet
A reference for the IBM i (AS/400, OS/400) command line, the work-with commands, libraries and objects, spooled files and output queues, messages, and 5250 function-key shortcuts.