PowerShell Cheat Sheet

A reference for Windows PowerShell, discovering cmdlets, the object pipeline, filtering and formatting, managing files, processes and services, plus variables and flow control.

A reference for Windows PowerShell. 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

CmdletWhat it does
Get-Command *service*Find cmdlets by name
Get-Help CMDLETShow help for a cmdlet
Get-MemberList an object's properties & methods
Get-AliasList shortcut aliases (e.g. ls, cd)

Files & navigation

CmdletWhat it does
Get-ChildItemList items (alias ls/dir)
Set-Location PATHChange directory (alias cd)
Get-Content FILERead a file (alias cat)
Set-Content FILE "text"Write text to a file
Copy-Item SRC DEST -RecurseCopy files or folders
Remove-Item PATH -Recurse -ForceDelete items (careful)
Test-Path PATHCheck if a path exists

The pipeline & filtering

CmdletWhat it does
Where-Object { $_.CPU -gt 10 }Filter objects by a condition
Select-Object Name, IdPick specific properties
Sort-Object CPU -DescendingSort objects
Measure-Object -SumCount / sum / average values
ForEach-Object { $_ * 2 }Run a block for each item
... | Format-Table -AutoSizeDisplay results as a table

System & processes

CmdletWhat it does
Get-ProcessList running processes
Stop-Process -Name app -ForceKill a process
Get-ServiceList Windows services
Start-Service -Name w32timeStart a service (Stop-Service to stop)
Get-ComputerInfoOS and hardware details

Variables & flow

SyntaxWhat it does
$x = 5Assign a variable
$items = @(1,2,3)Create an array
if ($x -gt 3) { ... }Conditional (-eq -ne -lt -gt -like)
foreach ($i in $items) { ... }Loop over a collection
Invoke-WebRequest URLDownload / call a URL (alias iwr)

Run scripts with .\script.ps1. If blocked, set the policy for your session: Set-ExecutionPolicy -Scope Process RemoteSigned. 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

  1. Browse by section.
  2. Find the cmdlet you need.
  3. Copy it with one tap.
  4. Adapt the parameters.

Example

Get-Process | Sort-Object CPU -Descending lists the busiest processes.

Sources & methodology

Last updated .

Frequently asked questions

What is a cmdlet?

A cmdlet is a built-in 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?

The execution policy may be blocking it. For the current session, run Set-ExecutionPolicy -Scope Process RemoteSigned, then run your script.

Do my old CMD commands still work?

Many do, because PowerShell defines aliases like ls, cd, and cat. For full functionality, learn the underlying cmdlets they point to.