How it works...
Sort-Object examines each individual object and determines the sort order. Sort-Object will try to use the object's Compare method if it is implemented, and will otherwise use an alphanumeric sorting. When using object properties to sort a collection of objects, always try to find something that can easily be sorted, such as strings, integers, and dates.
If the object cannot be sorted as easily, a script block or a hashtable may be used. With a script block as well as with a hashtable, we can make use of the built-in $_ parameter and its alias, $PSItem. $_, always points to the current element in the pipeline. In case a collection of objects is being piped, $_ will point to each individual object. This means that all object ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access