Introduction
The pipeline lets you send the output of one command directly into another command. It helps you do tasks step-by-step easily.
The pipeline lets you send the output of one command directly into another command. It helps you do tasks step-by-step easily.
command1 | command2 | command3
| sends output from the left command to the right command.Get-Process | Sort-Object CPU -Descending
Get-ChildItem | Where-Object { $_.Extension -eq ".txt" }Get-Service | Select-Object Name, Status
This script gets all processes, filters those using more than 1 CPU unit, and shows the first 3 with their name and CPU usage.
Get-Process | Where-Object { $_.CPU -gt 1 } | Select-Object -First 3 Name, CPUEach command in the pipeline runs one after another automatically.
Use $_ to refer to the current item in filtering commands like Where-Object.
Pipelines help avoid creating temporary files or variables for intermediate results.
The pipeline | connects commands so output flows from one to the next.
It makes scripts shorter and easier to read.
Use it to filter, sort, and select data step-by-step.
| do in PowerShell?| connects commands so the output of the first command flows as input to the next.| must connect commands properly; Get-Process | Sort-Object CPU uses it correctly.Sort-Object CPU, which Get-Process | Sort-Object CPU uses correctly.| between commands and correct parameter names [OK]Get-Process | Where-Object { $_.CPU -gt 100 } | Select-Object -First 1 -Property ProcessNameGet-Process gets all processes, Where-Object { $_.CPU -gt 100 } filters those with CPU > 100.Select-Object -First 1 -Property ProcessName picks the first such process and shows its name.Get-Service | Where-Object Status -eq 'Running' | Select Name
{ $_.Status -eq 'Running' }. The given command misses the braces.Select is an alias for Select-Object, so it's valid. Get-Service can be piped. Pipeline operator is present.Where-Object { $_.Status -eq 'Running' } to keep only running services.Sort-Object Status.Select-Object -First 3.Pass the test and this pattern moves unknown