Concept Flow - Sort-Object for ordering
Input Collection
Sort-Object Command
Compare Items
Reorder Items
Output Sorted Collection
Sort-Object takes a list, compares items, reorders them, and outputs the sorted list.
1..5 | Sort-Object -Descending "apple","banana","cherry" | Sort-Object
| Step | Input | Sort Direction | Action | Output |
|---|---|---|---|---|
| 1 | [1,2,3,4,5] | Descending | Compare numbers | [5,4,3,2,1] |
| 2 | ["apple","banana","cherry"] | Ascending | Compare strings alphabetically | ["apple","banana","cherry"] |
| 3 | N/A | N/A | End of sorting | Sorted collections output |
| Variable | Start | After Step 1 | After Step 2 | Final |
|---|---|---|---|---|
| Numbers | [1,2,3,4,5] | [5,4,3,2,1] | [5,4,3,2,1] | [5,4,3,2,1] |
| Strings | ["apple","banana","cherry"] | ["apple","banana","cherry"] | ["apple","banana","cherry"] | ["apple","banana","cherry"] |
Sort-Object sorts collections in PowerShell. Use -Descending to sort from largest to smallest. Default is ascending order (smallest to largest). Works on numbers, strings, and objects. Outputs a reordered collection.