PowerShell: Pipeline Commands

By Xah Lee. Date: . Last updated: .

These commands are almost always used by piping some command's output to them.

Foreach-Object (alias %, foreach)

do something for each object.

dir | ForEach-Object { $_.fullname}
Select-Object (alias select)

filter by object properties, or first few, or last few.

dir | select -first 5
Where-Object (alias ?, where)

filter by boolean test.

dir -recurse | where { $_.name.length -gt 40}
Select-String (alias sls)

Filter string objects by string pattern. [see Search String in Files]

Sort-Object (alias sort)

Sort

Format-List (alias fl)

Format object as list. Useful when PowerShell truncates file path.

dir -recurse | fl
Format-Table (alias ft)

Format object as table.

PowerShell, Command Pipeline