The Object Pipeline
Filter, select, sort, and transform objects flowing through the PowerShell pipeline.
Theory
Because PowerShell pipes objects, you manipulate data by its properties rather than by column position. The core verbs:
Where-Object— filter rows by a conditionSelect-Object— pick properties (columns), or-First/-LastNSort-Object— order by a propertyForEach-Object— run code per itemGroup-Object/Measure-Object— aggregate
Get-Member reveals which properties and methods an object exposes, so you always
know what you can filter or select on.
Real-World Example
# Services that are stopped but set to auto-start
Get-Service |
Where-Object { $_.Status -eq 'Stopped' -and $_.StartType -eq 'Automatic' } |
Select-Object Name, DisplayName |
Sort-Object Name
# Top 3 largest files, as JSON
Get-ChildItem -Recurse -File |
Sort-Object Length -Descending |
Select-Object -First 3 Name, Length |
ConvertTo-Json Hands-On Exercise
- List running services, showing only Name and Status.
- Find the three largest files in a folder tree.
- Group processes by name and count each group.
- Export a filtered list to CSV with
Export-Csv.
Cheat Sheet▾
| Task | Cmdlet |
|---|---|
| Filter | Where-Object { $_.Prop -eq x } |
| Select columns | Select-Object A, B |
| Top N | Select-Object -First N |
| Sort | Sort-Object Prop -Descending |
| Per-item code | ForEach-Object { … } |
| Group / count | Group-Object Prop |
| To/from JSON | ConvertTo-Json / ConvertFrom-Json |
Common Interview Questions▾
What does $_ mean in a PowerShell pipeline?
It’s the current pipeline object inside a script block, e.g. Where-Object { $_.Status -eq 'Running' }
filters on each incoming object’s Status property.
How do you select specific properties from objects?
Select-Object Name, Status returns objects with just those properties; add
-First N or -Last N to limit the count.
Official Documentation
📝 My notes on this topic
Auto-saves as you type