PowerShell: How Pipe Works

By Xah Lee. Date: . Last updated: .

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

Here are some examples:

# list current dir, sort it
dir | sort

# list, sort, show first 5 elements
dir | sort | select -first 5

# list, sort, select, then format for display
dir | sort | select -first 5 | ft name, length
# move jpg files to another dir
Get-Item $home/Documents/*jpg | mv -Destination $home/Pictures/
# filter out bot access from web log, save to new file
get-content weblog.txt |
select-string -notmatch "Googlebot" |
out-file -Encoding utf8 -width 999000 weblog2.txt

How Pipe Works

See also: Object Type, Properties, Methods

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

Common Pipeline Commands