PowerShell: Pipeline Commands

By Xah Lee. Date: . Last updated: .

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

Foreach

Foreach-Object (alias %, foreach)

do something for each object.

dir | ForEach-Object { $_.fullname}

Select

Select-Object (alias select)

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

dir | select -first 5

Filter (where)

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.

Sort

Sort-Object (alias sort)

Sort

Format Output

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