Sort an enumeration in either ascending or descending order
Synonyms:
Sort-Object
sort
Assuming:
$names = @( "Aaron", "Aaron", "Bernie", "Charlie", "Danny" )
Ascending sort is the default:
$names | Sort-Object
$names | sort
Aaron
Aaron
Bernie
Charlie
Danny
To request descending order:
$names | Sort-Object -Descending
$names | sort -Descending
Danny
Charlie
Bernie
Aaron
Aaron
You can sort using an expression.
$names | Sort-Object { $_.length }
Aaron
Aaron
Danny
Bernie
Charlie