Sort-Object is a PowerShell cmdlet for changing the order of input objects according to one or more property values. For example, it can put processes with the highest CPU usage first. section 8.6
Use the cmdlet to control ordering in a pipeline:
- Sort processes by CPU with Get-Process | Sort-Object CPU. section 8.6
- Add -Descending, or its abbreviation -desc, to place the largest values first. section 8.6
- Provide comma-separated properties such as CPU,ID to use a secondary ordering when values tie. section 8.6
- Sort files by CreationTime or LastWriteTime before selecting, exporting, or writing their results. section 8.11
Sort processes for review
Get-Process | Sort-Object CPU -Descending | Select-Object Name,ID,CPU sorts process objects by CPU while retaining them in the pipeline, then creates a smaller display object with the selected properties. section 8.8
Get-Process | Sort-Object CPU,ID -desc
Compare primary and secondary property sorting with descending order using a compact, runnable process pipeline. section 8.6
