0
0
PowerShellscripting~5 mins

Pipeline concept (|) in PowerShell

Choose your learning style9 modes available
Introduction

The pipeline lets you send the output of one command directly into another command. It helps you do tasks step-by-step easily.

You want to list files and then filter only certain ones.
You want to get a list of processes and sort them by memory usage.
You want to find text in a file and count how many times it appears.
You want to get system info and save only the parts you need.
You want to combine commands to automate a task without saving intermediate results.
Syntax
PowerShell
command1 | command2 | command3
The pipe symbol | sends output from the left command to the right command.
Each command works on the data it receives from the previous command.
Examples
This gets all running processes and sorts them by CPU usage from highest to lowest.
PowerShell
Get-Process | Sort-Object CPU -Descending
This lists all files and then filters only the ones with a .txt extension.
PowerShell
Get-ChildItem | Where-Object { $_.Extension -eq ".txt" }
This gets all services and shows only their name and status.
PowerShell
Get-Service | Select-Object Name, Status
Sample Program

This script gets all processes, filters those using more than 1 CPU unit, and shows the first 3 with their name and CPU usage.

PowerShell
Get-Process | Where-Object { $_.CPU -gt 1 } | Select-Object -First 3 Name, CPU
OutputSuccess
Important Notes

Each 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.

Summary

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.