The essentials
Quick reference
One focused task per row. Jump to the related section for complete, working examples.
| Use | Syntax | Examples |
|---|---|---|
| Inspect object members | Get-Process | Get-Member | View examples |
| Inspect one object | Get-Process | Select-Object -First 1 | Format-List * | View examples |
| Filter by one property | Get-Process | Where-Object CPU -gt 10 | View examples |
| Filter with a script block | Get-Service |
Where-Object { $_.Status -eq 'Running' -and $_.CanStop } | View examples |
| Select properties | Get-Process | Select-Object Name, Id | View examples |
| Take the first objects | Get-Process | Select-Object -First 5 | View examples |
| Expand one property | Get-Process | Select-Object -ExpandProperty Name | View examples |
| Calculate a property | Get-Process |
Select-Object Name, @{Name='MemoryMB'; Expression={[math]::Round($_.WorkingSet64 / 1MB, 1)}} | View examples |
| Sort descending | Get-Process | Sort-Object WorkingSet64 -Descending | View examples |
| Transform each object | Get-Process |
ForEach-Object { $_.Name.ToUpperInvariant() } | View examples |
| Group by a property | Get-Service | Group-Object Status | View examples |
| Measure numeric values | Get-ChildItem -File |
Measure-Object Length -Sum -Average | View examples |
| Save and continue | Get-Process |
Tee-Object -Variable processes |
Sort-Object CPU -Descending | View examples |
| Export objects to CSV | Get-Process |
Select-Object Name, Id, CPU |
Export-Csv processes.csv -NoTypeInformation | View examples |
| Import CSV objects | Import-Csv processes.csv | View examples |
| Format a final table | Get-Process |
Sort-Object CPU -Descending |
Format-Table Name, Id, CPU -AutoSize | View examples |
| Run an action per object | Get-ChildItem *.log |
ForEach-Object { Compress-Archive -LiteralPath $_.FullName -DestinationPath ($_.FullName + '.zip') } | View examples |
PowerShell pipelines pass structured objects between commands rather than passing only display text. Inspect those objects, filter early, select the properties you need, and reserve formatting commands for the end of interactive output.
Step by step
Detailed examples
Inspect what the pipeline contains
Get-Member reveals the .NET type and available properties and methods. Select one representative object and format every property when you need to see actual values. This inspection step prevents guesswork when building filters and calculated properties.
Get-Process | Get-Member Get-Process |
Select-Object -First 1 |
Format-List * Note: Format-List is appropriate here because display is the final goal; do not place it before commands that need the original process objects.
Filter objects by their properties
Where-Object keeps inputs for which a condition is true. The comparison-statement form is concise for one property, while a script block supports multiple tests and uses $_ for the current object. Filter as early as practical to reduce later work.
Get-Process |
Where-Object CPU -gt 10 |
Select-Object Name, Id, CPU Get-Service |
Where-Object {
$_.Status -eq 'Running' -and $_.CanStop
} |
Select-Object Name, DisplayName, Status Shape objects for the next command
Select-Object can choose properties, limit the number of objects, expand a single property's value, or create calculated properties. Unlike formatting commands, selection produces objects that later commands can still sort, filter, measure, or export.
Get-Process |
Select-Object -First 10 Name, Id, @{
Name = 'MemoryMB'
Expression = { [math]::Round($_.WorkingSet64 / 1MB, 1) }
} $names = Get-Service |
Where-Object Status -eq 'Running' |
Select-Object -ExpandProperty Name
$names.GetType().FullName Note: Use -ExpandProperty when the next command needs raw property values rather than custom objects containing that property.
Sort objects and transform values
Sort-Object orders whole objects using one or more properties. ForEach-Object runs a script block for every input and emits any resulting values. When the block performs changes, test the input pipeline first and use commands that support -WhatIf where available.
Get-Process |
Sort-Object WorkingSet64 -Descending |
Select-Object -First 10 Name, Id, WorkingSet64 Get-Process |
Select-Object -ExpandProperty Name |
ForEach-Object { $_.ToUpperInvariant() } |
Sort-Object -Unique Get-ChildItem -File -Filter '*.log' |
ForEach-Object {
$destination = $_.FullName + '.zip'
Compress-Archive -LiteralPath $_.FullName -DestinationPath $destination
} Note: This example writes archives. Inspect the Get-ChildItem results before running it and decide how existing destination files should be handled.
Group and measure pipeline data
Group-Object returns one group object per distinct property value, including its count and members. Measure-Object calculates counts and optional numeric statistics without retaining every input for display.
Get-Service |
Group-Object Status |
Sort-Object Count -Descending |
Select-Object Name, Count $summary = Get-ChildItem -File |
Measure-Object Length -Sum -Average
$summary | Select-Object Count, Sum, Average Capture output without ending the pipeline
Tee-Object stores the objects it receives in a variable or file and also sends them to the next command. A variable preserves the live objects for later inspection, while writing to a file produces formatted text unless another serialization command is used.
Get-Process |
Tee-Object -Variable processes |
Sort-Object WorkingSet64 -Descending |
Select-Object -First 5 Name, WorkingSet64
$processes | Measure-Object Note: The variable contains the same kind of process objects that entered Tee-Object, not the final selected display rows.
Export reusable object data
Export-Csv serializes object properties into CSV columns. Select stable properties first, use -NoTypeInformation for a clean header, and remember that Import-Csv reconstructs property values as strings rather than restoring the original .NET object type.
Get-Process |
Select-Object Name, Id, CPU, WorkingSet64 |
Export-Csv -Path './processes.csv' -NoTypeInformation -Encoding utf8 Import-Csv './processes.csv' |
Where-Object { [double]$_.CPU -gt 10 } |
Sort-Object { [double]$_.CPU } -Descending Note: CSV fields are strings after import, so cast numeric values before numeric comparisons or sorting.
Format only at the display boundary
Format-Table and Format-List produce formatting instructions for the display system, not ordinary domain objects. Put them at the end of an interactive pipeline. Use Select-Object instead when data will continue to another command, be exported, or be returned from a function.
Get-Process |
Where-Object CPU -gt 10 |
Sort-Object CPU -Descending |
Format-Table Name, Id, CPU -AutoSize Get-Process |
Select-Object Name, Id, CPU |
Export-Csv './processes.csv' -NoTypeInformation Note: Do not insert Format-Table before Export-Csv; the CSV would describe formatting records instead of process properties.
Sources and further reading
References
Authoritative documentation used to verify and expand this cheat sheet.
- Microsoft LearnWork with the Windows PowerShell pipelinelearn.microsoft.com
- Microsoft LearnRemoving Objects from the Pipeline with Where-Objectlearn.microsoft.com
- Microsoft LearnExport-Csvlearn.microsoft.com
- Microsoft LearnMeasure-Objectlearn.microsoft.com
- Microsoft LearnGroup-Objectlearn.microsoft.com
Help us improve
Found a typo or missing example?
Tell us what would make this cheat sheet clearer, more complete, or more useful.



