What Is the PowerShell Pipeline?
The pipe character | in PowerShell connects cmdlets so the output of one becomes the input of the next, but unlike traditional shells it never converts that output to text in between. Each stage receives fully structured .NET objects with their properties and methods intact, so downstream commands can query exact fields such as .CPU or .Status instead of scraping columns out of formatted text.
Cricket analogy: DRS review passes structured ball-tracking data (trajectory, pitch point) between hardware and third umpire, not just a verbal description — like PowerShell passing objects not text.
How Objects Flow Through the Pipeline
PowerShell processes pipeline objects one at a time in a streaming fashion rather than waiting to collect an entire result set first. As soon as Get-Process emits a single process object, it can already be evaluated by Where-Object and passed onward, which keeps memory usage low and lets you see results appear incrementally even for very large collections.
Cricket analogy: Ball-by-ball commentary data streams from the stadium sensors to the broadcast graphics engine one delivery at a time, updating stats live rather than waiting for the innings to end.
Get-Process |
Where-Object { $_.CPU -gt 100 } |
Sort-Object CPU -Descending |
Select-Object -First 5 Name, CPU, IdThe Pipeline vs Traditional Shell Piping
In shells like bash, a pipe connects the standard output text of one program to the standard input text of the next, so every downstream command must parse that text with tools like awk, sed, or regular expressions, and any change in column width or locale can silently break the script. PowerShell sidesteps this entirely because the object crossing the pipe already carries typed, named properties, so Where-Object { $_.Status -eq 'Running' } reads a real property instead of guessing which text column holds the status.
Cricket analogy: Comparing DRS's structured ball-tracking to a commentator guessing LBW from a TV replay by eye — one has exact data, the other requires error-prone re-interpretation, like text piping needing regex parsing.
Inside a script block on the pipeline, $_ refers to the current object being processed. $PSItem is an identical, more readable alias for the same variable — use whichever reads more clearly in context; they behave exactly the same way.
Building Multi-Stage Pipelines
Well-designed PowerShell pipelines chain several small, single-purpose cmdlets rather than one command doing everything, mirroring the Verb-Noun naming convention where each cmdlet's name tells you exactly what one job it does. A typical reporting pipeline might filter with Where-Object, sort with Sort-Object, then trim the output with Select-Object, each stage transforming the object stream a little further toward the final result.
Cricket analogy: A bowling attack works in stages — new-ball swing bowler, then a spinner to build pressure, then a death-overs specialist — each doing one job well, like chained single-purpose cmdlets.
The ForEach-Object cmdlet streams objects one at a time and is pipeline-friendly, but the foreach statement loads the entire collection into memory before looping. For very large data sets, prefer ForEach-Object inside a pipeline to keep memory usage flat and results streaming.
- The
|operator passes whole .NET objects between cmdlets, not text. - Objects stream through the pipeline one at a time rather than being collected in bulk first.
- Because data stays structured, downstream cmdlets query exact properties instead of parsing text columns.
$_and$PSItemboth refer to the current pipeline object inside a script block.- Pipelines are built from small, single-purpose cmdlets following the Verb-Noun naming pattern.
- Prefer
ForEach-Objectover theforeachstatement inside pipelines to keep memory usage low on large collections.
Practice what you learned
1. What actually travels across the `|` pipe operator in PowerShell?
2. Inside a pipeline script block, what does `$_` refer to?
3. Why is text-based piping in traditional shells considered fragile compared to PowerShell's approach?
4. Which cmdlet streams objects one at a time through a pipeline, keeping memory usage low on large collections?
Was this page helpful?
You May Also Like
Working with Objects
Understand how every piece of PowerShell output is a typed .NET object with properties and methods, and learn to inspect, access, and build them.
Filtering and Selecting
Master Where-Object for keeping only the rows you need and Select-Object for keeping only the properties you need, plus the operators that power both.
Sorting and Grouping
Learn to order pipeline output with Sort-Object and cluster it into buckets with Group-Object, including combining both with Measure-Object for reports.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics