訂購排序物件排序

按升序或降序對列舉進行排序

別名:

Sort-Object
sort

假設:

$names = @( "Aaron", "Aaron", "Bernie", "Charlie", "Danny" )

升序排序是預設值:

$names | Sort-Object
$names | sort

Aaron
Aaron
Bernie
Charlie
Danny

要求降序:

$names | Sort-Object -Descending
$names | sort -Descending

Danny
Charlie
Bernie
Aaron
Aaron

你可以使用表示式排序。

$names | Sort-Object { $_.length }

Aaron
Aaron
Danny
Bernie
Charlie