Cheat Sheet Library

PowerShell Cheat Sheet

PowerShell pipes objects between commands, not text. Commands follow a Verb-Noun pattern. Works on Windows PowerShell 5.1 and PowerShell 7+ (pwsh).

  • 71 entries
  • 11 sections
  • Updated
  • Reviewed
  • Click a command to see all its options

71 entries

On this page

Getting Help #

CommandAction
Show examples for a command
Find commands by name
Show the properties and methods of the output
See what an alias points to
Download help files (admin only in Windows PowerShell 5.1)

Common Aliases #

AliasReal command
, ( only on Windows)
(Windows only)
/ / / / (Windows only)
/ / (Windows only)

Files & Folders #

CommandAction
List, including hidden files
Find files recursively
Create a file
Create a folder ( also works)
Delete a folder and its contents (permanent, no Recycle Bin, no prompt)
Copy a folder
Rename
Follow a log file (like )
Write (overwrite)
Append
Check whether a path exists
Search text in files (like grep)
Create a zip
Extract a zip
File checksum
Open the current folder in Explorer ()

Pipeline #

CommandAction
Filter ($_ = current item)
Pick properties / first N
Sort
Group and count
Count, sum, average
Run code for each item
Table output
Show all properties
Interactive, filterable window (Windows)
Save as CSV
Read a CSV as objects
/ JSON conversion

Comparison Operators #

OperatorMeaning
-eq -neEqual / not equal
-gt -ge -lt -leGreater / less than (or equal)
-like "*.txt"Wildcard match
-match "^\d+$"Regex match
-contains / -inCollection contains a value
-and -or -notLogic

Processes & Services #

CommandAction
Top CPU processes
Kill a process by name
Start as administrator
Running services
Restart a service

Network #

CommandAction
Ping
Test whether a port is open
DNS lookup
IP configuration
Download a file
Call an API (parses JSON automatically)

Variables & Environment #

SyntaxMeaning
$name = "Milan"Set a variable
"Hello $name"Variables expand in double quotes (not in single quotes)
$env:PATHRead an environment variable
$env:API_KEY = "x"Set it for this session
$PROFILEPath to your profile script (runs at startup)
$? / $LASTEXITCODEDid the last command succeed? / exit code of the last program
$null, $true, $falseBuilt-in values

Script Basics #

function Get-Greeting([string]$Name = "World") {
    "Hello, $Name!"
}

foreach ($file in Get-ChildItem *.txt) {
    if ($file.Length -gt 1KB) { Write-Host "$($file.Name) is big" }
}

try { Get-Item missing.txt -ErrorAction Stop }
catch { Write-Warning $_.Exception.Message }

Keyboard (PSReadLine) #

KeyAction
Tab / Shift + TabCycle completions
Ctrl + SpaceShow all completions as a menu
Ctrl + RSearch history
F2Toggle inline / list prediction view (PSReadLine 2.2+, built into PS 7.3+)
→Accept inline suggestion
Ctrl + CStop the command

Tips #

  • Scripts blocked? Run Set-ExecutionPolicy -Scope CurrentUser RemoteSigned.
  • Line continuation: end the line with a backtick ` or with a pipe |.
  • Install PowerShell 7: winget install Microsoft.PowerShell.