What is a PowerShell cheatsheet?
PowerShell is a shell and scripting language where commands, called cmdlets, return objects instead of plain text. That is why Get-Process | Sort-Object CPU works without any text parsing: you sort a property, not a column. The price is a long vocabulary. Cmdlets follow a Verb-Noun pattern (Get-ChildItem, Set-Content, Stop-Service), and nobody keeps them all in their head. This cheatsheet is the short list you keep open next to the console: the cmdlet for the thing you want to do, ready to copy.
The commands are grouped in eight sections: help and discovery, files and folders, pipeline and objects, text and output, processes and services, network and web, variables, flow and functions, and modules and remoting. Each item has a plain description and one to three commands. Values you must replace are written between angle brackets, such as <file>, <folder>, <name> and <host>.
A warning that matters: PowerShell exists in two families. Windows PowerShell 5.1 ships with Windows. PowerShell 7 is cross-platform and also runs on Linux and macOS. Some cmdlets only exist on Windows, for example Get-Service, Get-WinEvent, Get-ComputerInfo, Resolve-DnsName, Test-NetConnection, the registry cmdlets and Out-GridView. The descriptions mark them with "(Windows)". A few others, such as ForEach-Object -Parallel and SSH remoting, need PowerShell 7. The page is plain reference material that runs in your browser, with no account and nothing sent anywhere. If you also work in a Unix shell, the Linux cheatsheet covers the same tasks there.
How to use the PowerShell cheatsheet
- Open the page and scroll. Sections follow a normal working order, from finding help to remoting.
- Press
/to jump to the search box, or click it. Type what you want to do or part of a cmdlet name. Every word has to match, sohash filefinds the item that computes a file hash. The search ignores accents and capital letters. - Use the section chips under the search box to jump to a section. While you search, only the sections with results stay in the chips.
- Press the round copy button next to an item to copy its commands, one per line.
- Press Copy section in a section title to copy every command of that section.
- Replace the placeholders in angle brackets and paste the command into your console. Read the description first: it says when a cmdlet is Windows only.
- Press Print to get a clean sheet on paper or PDF, without the buttons.
A counter at the bottom of the page shows how many items matched. If nothing matches, remove a word or try the cmdlet verb, such as get, remove or export.
Examples
Text operators
Item "Replace, split and join text":
"a-b-c" -replace "-", "_"
"a,b,c" -split ","
"a", "b", "c" -join ";"a_b_c
a
b
c
a;b;cThe operators work on strings and arrays. -split returns an array, so each part is printed on its own line.
Check a path before you delete it
Items "Check whether a path exists" and "Delete a file":
Test-Path .\old.log
Remove-Item .\old.log
Test-Path .\old.logTrue
FalseRemove-Item prints nothing when it works. Running Test-Path before and after confirms the file is gone.
Read JSON as objects
Items "Read JSON and CSV" and "Pick a single property value". Suppose config.json contains {"name":"web","port":8080}:
$cfg = Get-Content config.json -Raw | ConvertFrom-Json
$cfg.port
$cfg | ConvertTo-Json -Compress8080
{"name":"web","port":8080}-Raw reads the file as a single string, which ConvertFrom-Json needs. You can then use the dot to reach any property. To inspect the same JSON in a tree, use the JSON viewer.
Top processes by memory
Get-Process | Sort-Object WorkingSet -Descending | Select-Object -First 3 Name, IdName Id
---- --
chrome 4120
Code 9832
pwsh 2210Your names and numbers will differ. Notice that the pipeline passes objects: Select-Object keeps only the two properties you asked for.
Common errors and how to fix them
- File cannot be loaded because running scripts is disabled on this system: the execution policy blocks
.ps1files on Windows. Allow your own scripts withSet-ExecutionPolicy -Scope CurrentUser RemoteSigned. The policy does not apply on Linux and macOS. - The term 'Get-Service' is not recognized as the name of a cmdlet: the cmdlet does not exist on your system. Either you are on Linux or macOS and the cmdlet is Windows only, or its module is not installed. Check with
Get-Command *<word>*and install the module withInstall-Module <name> -Scope CurrentUser. - Remove-Item with -Recurse -Force deletes without asking: there is no recycle bin. Run
Get-ChildItem <folder> -Recursefirst to see what will go, and test withTest-Path. Adding-WhatIfto many cmdlets shows what would happen without doing it. - Stop-Process -Force kills a program and loses unsaved work: use
Get-Process -Name <name>to confirm which process you are about to stop. - A variable inside quotes prints as text or empty: double quotes expand
$name, single quotes do not. Use$(...)for expressions, as in"today is $(Get-Date -Format yyyy-MM-dd)". - Write-Host output cannot be piped: it only prints on screen. Use
Write-Outputwhen another command needs the value. - No command matches your search: all the words must match at once. Remove one, or try a verb such as get, set or remove.
Frequently asked questions
What is the difference between PowerShell and Windows PowerShell?
Windows PowerShell 5.1 is the version that comes with Windows and runs only there. PowerShell 7 is the newer, open source, cross-platform version, started with pwsh. Most cmdlets in this sheet work in both. $PSVersionTable shows which one you have.
How do I run a PowerShell script?
Type ./script.ps1 from the folder of the script. On Windows, the execution policy must allow it, see the error list above. Without ./ PowerShell will not run a script from the current folder.
How do I find out what a cmdlet does?
Get-Help <cmdlet> -Examples shows usage examples, and Update-Help downloads the full help files first. Get-Command *<word>* finds cmdlets by name.
Does this cheatsheet run my commands?
No. It only shows and copies text. You paste the commands into your own console.
Is Write-Host the same as Write-Output?
No. Write-Output sends objects down the pipeline, so another command can use them. Write-Host only writes to the screen, which is useful for colored messages.