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