PowerShell: How Pipe Works

By Xah Lee. Date: . Last updated: .

Example of Pipe

You can send one command's output to another command's input. This is called piping. you write it as: command1 | command2 | command3.

# list current dir, sort it
dir | sort

# list, sort, show first 5 elements
dir | sort | select -first 5
# move jpg files to another dir
dir -file *jpg | move ~/Pictures/
# filter out bot access from web log, save to new file
Get-Content weblog | Select-String -notmatch "Googlebot" | Out-File path -width 111222333 -NoNewLine weblog2 

How Pipe Works

See also: Object Type, Properties, Methods

PowerShell pipeline input 2021-05-23
help shows which parameter accept pipeline input

PowerShell, Command Pipeline