PowerShell Genie
Cheat sheet

PowerShell Cheat Sheet

Download the PowerShell syntax and commands cheat sheet (PDF) · 767 KB

Reference 8 min read One-page recall

A compact PowerShell quick reference for everyday administration, troubleshooting and automation — rebuilt from the complete cheat sheet PDF. Run the live pipeline demos: every result is computed in your browser from fictional sample data.

Essential command patterns

Ten patterns cover most daily work. Press Run pipeline on a demo to watch fictional objects flow through each stage — click a stage to inspect its rows.

1. Discover commands

1PS> Get-Command -Noun Process
2PS> Get-Help Get-Process -Examples

Discover what is actually available in your session before guessing names. Availability depends on installed modules.

2. Inspect objects — console columns are only a view

1PS> Get-Process | Get-Member
2PS> Get-Process | Select-Object -First 3 -Property Name, Id, CPU

The table you see is a view. The object keeps every property until you deliberately select or format them.

Get-Member lists these properties for any object you meet.

3. Filter — keep objects whose properties match

1PS> Get-Service | Where-Object { $_.Status -eq 'Running' }

Where-Object chooses objects (rows). It never changes the state of anything — it only keeps matches.

Get-Service | Where-Object { $_.Status -eq 'Running' }

Press Run — objects flow through each stage. Fictional sample data.

4. Sort, then limit — CPU here is cumulative seconds

1PS> Get-Process | Sort-Object CPU -Descending | Select-Object -First 3 Name, CPU

Top-N questions need an ordering first — -First is meaningless without a sort. CPU is accumulated processor time in seconds, not live CPU %.

Get-Process | Sort-Object CPU -Descending | Select-Object -First 3 Name, CPU

Press Run — objects flow through each stage. Fictional sample data.

5. Measure — working-set memory in bytes

1PS> Get-Process | Measure-Object -Property WorkingSet64 -Sum

WorkingSet64 is bytes. Convert units explicitly when you present the number to a human.

Get-Process | Measure-Object -Property WorkingSet64 -Sum

Press Run — objects flow through each stage. Fictional sample data.

6. Group — count services in each status

1PS> Get-Service | Group-Object Status | Select-Object Name, Count

Group-Object answers “how many of each” in one pass — no manual counting loops.

Get-Service | Group-Object Status | Select-Object Name, Count

Press Run — objects flow through each stage. Fictional sample data.

7. Files — inspect the current directory

1PS> Get-ChildItem -File | Select-Object Name, Length, LastWriteTime

-File skips directories. You still have objects — Length and LastWriteTime sort and filter cleanly.

8. Strings — double quotes expand, single quotes stay literal

1PS> $topic = 'PowerShell'
2PS> "Learning $topic"
3PS> 'Learning $topic'

Double-quoted strings expand variables; single-quoted strings preserve literal text. Pick deliberately.

$topic = 'PowerShell'

Pick a quoting style to evaluate it.

9. Export objects — never Format-Table before Export-Csv

1PS> Get-Process | Select-Object Name, Id, CPU | Export-Csv -LiteralPath ./processes.csv -NoTypeInformation

Export-Csv needs structured objects. Format-* output is display text — piping it to Export-Csv exports garbage.

10. Handle errors — catch sees terminating errors

1PS> try {
2PS> Get-Item -LiteralPath './missing-file.txt' -ErrorAction Stop
3PS> } catch {
4PS> $_.Exception.Message
5PS> }

-ErrorAction Stop promotes the error to terminating so catch can see it. Without it, catch never fires.

Four principles that prevent mistakes

01 · Discover before guessing

Use Get-Command and Get-Help to inspect the command that is actually available in your session.

02 · Keep objects structured

Filter, sort, select, measure, and export object properties. Never parse formatted console text when object properties exist.

03 · Filter before formatting

Where-Object chooses objects. Select-Object chooses properties or limits rows. Format-* is for final display only.

04 · Sort before top-N

If the question asks for the largest, smallest, busiest, or newest objects, sort first — then select the first rows.

Task index

Discover command syntax
Basics
Find commands by name
Basics
Inspect an object's properties
Basics
Filter objects by property
Basics
Sort results
Basics
Choose which properties to keep
Basics
List files and folders
Files
Copy files
Files
Verify a file's integrity
Files
Export a report to CSV
Files
Inspect services
Services
Restart a service
Services
disruptive · restarts the service
Inspect running processes
Processes
Query Windows inventory (CIM)
System
Read Windows event logs
System
Check disk space
Disk
List disk volumes and health
Disk
Inspect background job output
System
Open an interactive remote session
Remoting
Run a command on remote computers
Remoting
Query AD user accounts
Users
Restart a computer
System
destructive · preview with -WhatIf

Eight rules worth memorizing

  1. Inspect first.

    Use Get-Member when you do not know which properties an object exposes.

  2. Filter with properties.

    Where-Object should compare real properties such as Status, Name, CPU, or WorkingSet64.

  3. Select deliberately.

    Select-Object chooses properties and can limit rows — two different jobs.

  4. Sort before top rows.

    Top-N questions require an ordering before -First is meaningful.

  5. Export objects.

    Export-Csv must receive structured objects, never Format-Table output.

  6. Know units.

    WorkingSet64 is bytes; CPU is accumulated seconds. Convert explicitly.

  7. Know scope.

    Commands depend on Windows, modules, tenant context, permissions, and edition.

  8. Discover safely.

    Get-Help -Examples and Get-Command -Syntax are cheap ways to confirm intent before running anything that changes a system.

See the pipeline move

Six sketches from the complete cheat-sheet PDF, redrawn as step-through diagrams. Each plays once when it scrolls into view — step with ← → or the Prev / Next buttons.

SKETCH 01 · FROM THE PDF

Read a command like a sentence

Getaction–Processtarget-Name pwshdetail

Verb, noun, details — read a command left to right, like a sentence.

SKETCH 02 · FROM THE PDF

A row is a view, not the object

PROCESS OBJECTNameWindows PowerShellId42CPU12…and moreinspectSELECTName: pwshCPU: 12

Console columns are a view. The object keeps every property.

SKETCH 03 · FROM THE PDF

Where-Object is a sieve

BITSSpoolerWinRMStatus = RunningBITSWinRM

Filtering chooses rows. It never changes the state of anything.

SKETCH 04 · FROM THE PDF

Sort before taking the top rows

INPUTnotes · 5chrome · 30pwsh · 12DESCENDINGchrome · 30pwsh · 12notes · 5chrome · 30pwsh · 12take first 2 ↑

Top-N questions need an ordering before -First means anything.

SKETCH 05 · FROM THE PDF

Pass objects along the pipeline

GET3 objectsWHERE2 objectsSORTlargestSELECTfieldsnamed properties travel with each object

Each object travels the whole pipeline, properties intact.

SKETCH 06 · FROM THE PDF

Export objects, not a drawn table

OBJECTName: pwshCPU: 12Export-Csvno Format-*report.csvNameCPUWindows PowerShell12

Format-* is for final display. Export needs objects, not text.

Diagrams are conceptual illustrations, not executions. Demo data on this page is fictional.