Sort-Object
Use Sort-Object to order objects by property, ascending by default or -Descending; -Unique drops duplicates.
Documentation: Microsoft Learn — Sort-Object
Syntax
See the command anatomy
Inspect this authored example with fictional data in the bounded browser model. The numbered stages show how its objects change.
Get-Process | Sort-Object CPU -Descending- Stage 1Get-Process
Positional values or no named parameters - Stage 2Sort-Object
-Descending
The object workshop
Watch your command work.
Change the command. Step through the pipeline. Inspect what survives.
Browser simulation · fictional services · Ctrl+Enter to run
Object properties
Enable JavaScript to step through this example. The lessons and command reference remain available.
Your task: return the stopped service, with exactly Name and Status.
Follow the objects
Run the command to inspect each stage.
Try it
PowerShell example · browser support is limited.
Execution scope: The full example below requires PowerShell outside this browser. You can edit this runner to use the supported practice commands; unsupported syntax returns an explanation.
Follow the objects
Run the command to inspect each stage.
Examples
Sort by CPU
Show reference output
Illustrative output · values vary by environment
Name ProcessName Id CPU WS WorkingSet WorkingSet64 ------- ----------- ----- ------ --------- ---------- ------------ MsMpEng MsMpEng 2600 950 220200960 220200960 220200960 chrome chrome 9184 842.31 486539264 486539264 486539264 pwsh pwsh 11268 18.27 78643200 78643200 78643200 spoolsv spoolsv 4400 1.4 33554432 33554432 33554432 notepad notepad 3200 0.4 12582912 12582912 12582912
Sort by Status
Show reference output
Illustrative output · values vary by environment
Status Name DisplayName ------ ---- ----------- Running BITS Background Intelligent Transfer Service Running Dnscache DNS Client Running WinRM Windows Remote Management Stopped Spooler Print Spooler
Parameters
Parameter definitions:
-Property-Descending-Unique
Practical use and troubleshooting
Practical scenario: Use Sort-Object when you need to order objects by property, ascending by default or -Descending; -Unique drops duplicates. Start with one identified target and inspect the returned values before extending the operation to a list. Keep the identity in your report so you can trace each result back to the object or path that produced it.
Common error and fix: Numbers stored as strings can sort lexically rather than numerically. Inspect the property type and convert the value deliberately before sorting when numeric order is required. In an unattended script, capture this failure with its original error record and record which target failed. An empty result and an unsuccessful query must remain distinguishable in the final report.
See also: Group-Object. Sort-Object orders objects by property values; Group-Object collects objects sharing a key. A grouped result contains groups and is not the original flat list in a new order. Read the linked command before substituting it; similar names do not imply identical inputs or output.
Put this command to work
Sort service names
Return all services ordered by Name.
The sandbox is visible now. Sign in with Google only when you run or check a task; commands and temporary files are discarded when you leave.
Run a command to inspect its result.
Inspect starting data
Supported syntax
Virtual files
Recap
Sort-Object Use Sort-Object to order objects by property, ascending by default or -Descending; -Unique drops duplicates.
Next: Measure-Object