PowerShell對象排序(結合哈希表)

能夠經過使用哈希表數組中對不一樣屬性進行不一樣的順序進行排序。數組

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

哈希表中進行排序的鍵可縮寫以下所示:ide

Sort-Object @{ e = 'LastWriteTime'; d = $true }, @{ e = 'Name'; a = $true }

您也能夠關注下方微信公衆號獲取更多資訊
PowerShell對象排序(結合哈希表)code

相關文章
相關標籤/搜索