October 2017
Intermediate to advanced
440 pages
11h 47m
English
The Sort-Object command allows objects to be sorted on one or more properties.
By default, Sort-Object will sort numbers in ascending order:
PS> 5, 4, 3, 2, 1 | Sort-Object12345
Strings are sorted in ascending order, irrespective of uppercase or lowercase:
PS> 'ccc', 'BBB', 'aaa' | Sort-ObjectaaaBBBccc
When dealing with complex objects, Sort-Object may be used to sort based on a named property. For example, processes may be sorted based on the Id property:
Get-Process | Sort-Object -Property Id
Objects may be sorted on multiple properties; for example, a list of files may be sorted on LastWriteTime and then on Name:
Get-ChildItem C:\Windows\System32 |
Sort-Object LastWriteTime, Name
In the preceding example, items ...
Read now
Unlock full access