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

相关文章
相关标签/搜索