PowerShell One-Liners That Pay Off
PowerShell passes objects, not text — once that clicks, a few one-liners replace a lot of clicking around in Windows.
PowerShell's big idea separates it from every Unix shell: commands pass objects, not lines of text. That one difference is what makes its pipelines so powerful.
Objects, not text
In bash you parse text with awk/cut. In PowerShell each item is an object with named properties, so you select and sort by name — no parsing:
Get-Process | Sort-Object WorkingSet -Descending | Select-Object -First 5 Name, WorkingSetGet-Process emits process objects; the pipeline sorts them by a real property and shows the top five. No fragile column-counting.
The verb-noun pattern
Cmdlets are named Verb-Noun, which makes them guessable: Get-Service, Stop-Process, Get-ChildItem, Set-Content. Discover them with:
Get-Command *network* # find relevant cmdlets
Get-Help Get-Process -Examples # see usage examples
Get-Process | Get-Member # list an object's properties and methodsGet-Member is the one to lean on — it shows you exactly what properties you can select, sort or filter on.
One-liners worth keeping
# Services that are running
Get-Service | Where-Object Status -eq 'Running'
# Export running services to CSV
Get-Service | Where-Object Status -eq 'Running' |
Select-Object Name, DisplayName | Export-Csv services.csv -NoTypeInformation
# Top 5 processes by memory
Get-Process | Sort-Object WS -Descending | Select-Object -First 5 Name, WS
# Find large files under a folder
Get-ChildItem C:\Logs -Recurse -File |
Sort-Object Length -Descending | Select-Object -First 10 FullName, Length
# Last 20 errors from the System event log
Get-WinEvent -LogName System -MaxEvents 20 |
Where-Object LevelDisplayName -eq 'Error'Filter left, format right
A performance habit: filter early with Where-Object so later stages handle fewer objects, and keep Format-* cmdlets last — they turn objects into display text, so nothing useful can come after them.
Takeaways
- PowerShell pipes objects with named properties, so you select/sort/filter without text parsing.
- Cmdlets follow Verb-Noun;
Get-Command,Get-Help -ExamplesandGet-Memberare your map. - Filter early with
Where-Object; putFormat-*last. - Treat unknown PowerShell commands as untrusted — read before you run.