可以通過使用哈希表數(shù)組中對不同屬性進行不同的順序進行排序。
Get-ChildItem | Sort-Object -Property @{ Expression = 'LastWriteTime'; Descending = $true }, @{ Expression = 'Name'; Ascending = $true } | Format-Table -Property LastWriteTime, Name
為了提高可讀性,可以將哈希表放到一個單獨的變量:
$order = @( @{ Expression = 'LastWriteTime'; Descending = $true } @{ Expression = 'Name'; Ascending = $true } ) Get-ChildItem | Sort-Object $order | Format-Table LastWriteTime, Name
哈希表中進行排序的鍵可縮寫如下所示:
Sort-Object @{ e = 'LastWriteTime'; d = $true }, @{ e = 'Name'; a = $true }
您也可以關(guān)注下方微信公眾號獲取更多資訊