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}
# list jpg files
dir -recurse -file | where { $_.name -iMatch "\.jpg|\.jpeg|\.jfif"}
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 in Depth

Path

Pipe

Comment

Value Types

String

Variable

Boolean

Conditional

Data Structure

Loop and Iteration

Input/Output

Function

Profile and Script

Script Examples

Misc