โšกPowerShellWiki
โ† All cheat sheets
๐Ÿ”ง

Pipeline & Filtering

Select, sort, group, and aggregate objects in the pipeline.

Selecting and shaping

Pick specific properties

Keep only the columns you care about.

Get-Process | Select-Object Name, Id, CPU

Get the top N items

Take the first few results.

Get-Process | Sort-Object CPU -Descending | Select-Object -First 5

Add a calculated property

Create a new column from an expression.

Get-Process | Select-Object Name,
    @{ Name = "MemMB"; Expression = { [math]::Round($_.WorkingSet / 1MB, 1) } }

Get unique values

Remove duplicates from a set.

Get-Process | Select-Object -ExpandProperty Company -Unique

Sorting and grouping

Sort by a property

Order results ascending or descending.

Get-ChildItem | Sort-Object Length -Descending

Group by a property

Bucket items and count each group.

Get-Process | Group-Object Company | Sort-Object Count -Descending

Aggregating

Count, sum, and average

Compute statistics over a property.

Get-ChildItem -File | Measure-Object Length -Sum -Average -Maximum

Count matching items

How many items pass a filter.

(Get-Service | Where-Object Status -eq 'Running').Count

Related cheat sheets