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.
Quick reference — reach for these first
Get-Help CMDLET -ExamplesFull syntax plus runnable examples; add -Online to open the docs page in a browser.CMDLET | Get-MemberReveal an object's real TypeName, properties, and methods — the key to using the pipeline.... | Where-Object WS -gt 1GBFilter objects by a property value (the grep of the object pipeline).... | Select-Object Name,Id -First 5Pick or reshape properties, take -First/-Last, or add calculated columns.Invoke-RestMethod URLCall a JSON/REST API and get back objects (not text) — properties are ready to pipe.bash pipes text, PowerShell pipes objects
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
| Task | Command | What to check |
|---|---|---|
| Get help with runnable examples for a cmdlet | Get-Help Get-ChildItem -Examples | EXAMPLES 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 methods | Get-Process | Get-Member | TypeName System.Diagnostics.Process with Property/Method members |
| List files as objects (ls equivalent) | Get-ChildItem -Path PATH -Recurse -File | FileInfo rows showing Length and LastWriteTime |
| Filter objects by a property | Get-ChildItem | Where-Object Length -gt 1MB | Only files larger than 1MB remain |
| Shape output with a calculated column | Get-Process | Select-Object Name,Id,@{n='MB';e={[int]($_.WS/1MB)}} | An MB column derived from the WS property |
| Sort objects by a property | Get-Process | Sort-Object CPU -Descending | Highest-CPU process appears first |
| Iterate one action per object | Get-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 error | try { 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 -WhatIf | Shows a 'What if' preview line; nothing is deleted |
| Allow local scripts to run (CHANGES CONFIG / per-user) | Set-ExecutionPolicy -Scope CurrentUser RemoteSigned | Get-ExecutionPolicy -Scope CurrentUser returns RemoteSigned |
| Import a module to expose its cmdlets | Import-Module MODULE ; Get-Command -Module MODULE | The module's cmdlets now appear and are callable |
Find the top memory processes, then act — because they are objects
objects-pipeline
Get-Process | Sort-Object WS -Descending | Select-Object -First 5 Name,Id,WS
# Name Id WS
# chrome 4821 1834567680
# pwsh 9120 612368384
# ...Get-Process chrome | Get-Member -MemberType Property
# TypeName: System.Diagnostics.Process
# Id Property int Id {get;}
# WS Property long WS {get;}Get-Process | Where-Object WS -gt 1GB | Stop-Process -WhatIf
# What if: Performing the operation "Stop-Process" on target "chrome (4821)".Stop-Process -Id 4821 -Confirm
Get-Process -Id 4821 -ErrorAction SilentlyContinue
# (no output) -> process 4821 is goneTroubleshooting — symptom → first check → next check
| Symptom | First check | Establishes | Next check |
|---|---|---|---|
| Script won't run: 'cannot be loaded because running scripts is disabled on this system' | Get-ExecutionPolicy -List | Whether the execution policy blocks local or remote scripts for your scope | Set-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 exists | Get-Command TERM | Whether the cmdlet's module is loaded or installed at all | Import-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 TypeName | Whether 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 breaks | Write-Output $PATH to see the actual value | Single vs double quotes — $ interpolates only inside double quotes | Single-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 service | whoami /groups (look for an elevated / Administrators token) | Whether the session has admin rights for that resource | Relaunch elevated: Start-Process pwsh -Verb RunAs, then retry the command |
| try/catch never fires even though the cmdlet clearly errored | Check $ErrorActionPreference and whether the error is terminating | Non-terminating errors flow past catch by default | Add -ErrorAction Stop to the cmdlet (or set $ErrorActionPreference='Stop') to make it catchable |
References
- Get-Help (Microsoft Learn)learn.microsoft.com
- about_Execution_Policieslearn.microsoft.com
- Invoke-RestMethodlearn.microsoft.com
- about_Try_Catch_Finallylearn.microsoft.com
- Get-Memberlearn.microsoft.com
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.