← All cheatsheets

Shell

PowerShell — the Windows automation shell

A fast-lookup reference for PowerShell: the pipeline passes .NET OBJECTS (not text like bash), so you filter, shape, and act by property — plus Get-Help/Get-Member discovery, REST calls, error handling, and execution policy.

Docs-checkedpowershellwindowsscriptingobjectscmdlets

Quick reference — reach for these first

Get-HelpGet-Help CMDLET -ExamplesFull syntax plus runnable examples; add -Online to open the docs page in a browser.
Get-MemberCMDLET | Get-MemberReveal an object's real TypeName, properties, and methods — the key to using the pipeline.
Where-Object... | Where-Object WS -gt 1GBFilter objects by a property value (the grep of the object pipeline).
Select-Object... | Select-Object Name,Id -First 5Pick or reshape properties, take -First/-Last, or add calculated columns.
Invoke-RestMethodInvoke-RestMethod URLCall a JSON/REST API and get back objects (not text) — properties are ready to pipe.

bash pipes text, PowerShell pipes objects

bash pipes text, PowerShell pipes objectsTop lane: bash streams raw text between commands, so each stage re-parses strings by column. Bottom lane: PowerShell streams .NET objects carrying named properties, so later stages filter and act by property without parsing.The pipe carries data — but what kind?bash → text streamps auxgrep nodeawk '{print $2}'"chrome 48…"re-parse colsPowerShell → object streamGet-ProcessWhere-ObjectStop-Process.Name .Id .WSWS -gt 1GB-Id by property[Process][Process]Objects keep their properties down the whole pipeline — no string parsing, so you can act on .Id directly.

Text equivalent: Two stacked pipelines. Top: bash runs ps aux into grep node into awk, passing raw text so each stage must re-parse columns. Bottom: PowerShell runs Get-Process into Where-Object into Stop-Process, passing Process objects that keep named properties like Name, Id, and WS, so a later stage can filter on WS and stop a process by its Id without parsing text.

Common tasks

Task · Command · What to check

TaskCommandWhat to check
Get help with runnable examples for a cmdletGet-Help Get-ChildItem -ExamplesEXAMPLES section prints copy-ready commands
Find a cmdlet by noun (Verb-Noun naming)Get-Command *Process*List includes Get-Process and Stop-Process
Inspect an object's properties and methodsGet-Process | Get-MemberTypeName System.Diagnostics.Process with Property/Method members
List files as objects (ls equivalent)Get-ChildItem -Path PATH -Recurse -FileFileInfo rows showing Length and LastWriteTime
Filter objects by a propertyGet-ChildItem | Where-Object Length -gt 1MBOnly files larger than 1MB remain
Shape output with a calculated columnGet-Process | Select-Object Name,Id,@{n='MB';e={[int]($_.WS/1MB)}}An MB column derived from the WS property
Sort objects by a propertyGet-Process | Sort-Object CPU -DescendingHighest-CPU process appears first
Iterate one action per objectGet-ChildItem *.log | ForEach-Object { $_.FullName }Full path printed for each .log file
Call a JSON API and keep objects$r = Invoke-RestMethod URL ; $r.PROPERTY$r is an object; $r.PROPERTY returns a typed value, no manual parsing
Search file contents (grep equivalent)Select-String -Path *.log -Pattern 'ERROR'Matching lines returned with file name and line number
Handle a terminating errortry { Get-Item PATH -ErrorAction Stop } catch { "handled: $($_.Exception.Message)" }Prints a handled message instead of a red terminating error
Preview a delete before running it (DESTRUCTIVE)Remove-Item PATH -WhatIfShows a 'What if' preview line; nothing is deleted
Allow local scripts to run (CHANGES CONFIG / per-user)Set-ExecutionPolicy -Scope CurrentUser RemoteSignedGet-ExecutionPolicy -Scope CurrentUser returns RemoteSigned
Import a module to expose its cmdletsImport-Module MODULE ; Get-Command -Module MODULEThe module's cmdlets now appear and are callable

Find the top memory processes, then act — because they are objects

objects-pipeline

1
Problem: a Windows box is sluggish. You need the biggest memory consumers and a safe way to kill one, without text-parsing.
2
List processes as objects, sorted by working set (WS), top 5. The output is objects, not formatted text.
Get-Process | Sort-Object WS -Descending | Select-Object -First 5 Name,Id,WS
# Name     Id     WS
# chrome   4821   1834567680
# pwsh     9120    612368384
# ...
3
Prove it's objects: inspect the members you can pipe on (every row carries .Id, .WS, etc.).
Get-Process chrome | Get-Member -MemberType Property
# TypeName: System.Diagnostics.Process
# Id    Property  int Id {get;}
# WS    Property  long WS {get;}
4
Preview the destructive action first — target the Id property directly (DESTRUCTIVE if run without -WhatIf).
Get-Process | Where-Object WS -gt 1GB | Stop-Process -WhatIf
# What if: Performing the operation "Stop-Process" on target "chrome (4821)".
5
Act with confirmation (DESTRUCTIVE — terminates the process).
Stop-Process -Id 4821 -Confirm
6
Verify: the process is gone. No output means it no longer exists; -ErrorAction keeps the check quiet.
Get-Process -Id 4821 -ErrorAction SilentlyContinue
# (no output) -> process 4821 is gone

Troubleshooting — symptom → first check → next check

SymptomFirst checkEstablishesNext check
Script won't run: 'cannot be loaded because running scripts is disabled on this system'Get-ExecutionPolicy -ListWhether the execution policy blocks local or remote scripts for your scopeSet-ExecutionPolicy -Scope CurrentUser RemoteSigned (per-user, no admin). Avoid a permanent Bypass.
'TERM is not recognized as the name of a cmdlet' though you know it existsGet-Command TERMWhether the cmdlet's module is loaded or installed at allImport-Module MODULE, or Install-Module MODULE if it is missing from the system
Pipeline yields plain text and Where-Object/Select-Object properties come back empty... | Get-Member and read the TypeNameWhether upstream is a native .exe (emits strings) rather than a cmdlet (emits objects)Use the cmdlet equivalent, or parse the text with ConvertFrom-Json / ConvertFrom-Csv / Select-String
A path with spaces or a $variable inside quotes expands wrong or breaksWrite-Output $PATH to see the actual valueSingle vs double quotes — $ interpolates only inside double quotesSingle-quote literals, double-quote when you want interpolation; use the & call operator to run a quoted exe path
'Access is denied' on Stop-Process, Remove-Item, or a servicewhoami /groups (look for an elevated / Administrators token)Whether the session has admin rights for that resourceRelaunch elevated: Start-Process pwsh -Verb RunAs, then retry the command
try/catch never fires even though the cmdlet clearly erroredCheck $ErrorActionPreference and whether the error is terminatingNon-terminating errors flow past catch by defaultAdd -ErrorAction Stop to the cmdlet (or set $ErrorActionPreference='Stop') to make it catchable

References

Examples target PowerShell 7+ (pwsh) and work cross-platform; execution policy, some providers, and "run as Administrator" are Windows-specific. Run elevated only where a step says so. Replace CAPS placeholders (CMDLET, URL, PATH, ID, MODULE) with real values.