100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Programming

The PowerShell Pipeline

Learn how PowerShell chains cmdlets together by passing live .NET objects from one stage to the next, instead of parsing plain text like traditional shells.

Pipeline & ObjectsBeginner9 min readJul 10, 2026
Analogies

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.

powershell
Get-Process |
    Where-Object { $_.CPU -gt 100 } |
    Sort-Object CPU -Descending |
    Select-Object -First 5 Name, CPU, Id

The 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 $PSItem both 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-Object over the foreach statement inside pipelines to keep memory usage low on large collections.

Practice what you learned

Was this page helpful?

Topics covered

#Programming#PowerShellStudyNotes#ThePowerShellPipeline#PowerShell#Pipeline#Objects#Flow#DevOps#StudyNotes#SkillVeris