【问题标题】:Ascending and Descending on Powershell queryPowershell查询的升序和降序
【发布时间】:2018-06-10 23:44:32
【问题描述】:

以下查询将列出 power shell 中的 cmdlet。

get-command -CommandType cmdlet | Group-Object -Property verb

因为我需要按降序对列数进行排序,然后按升序对列进行命名。以下查询未给出预期结果。

get-command -CommandType cmdlet | Group-Object -Property verb | Sort-Object Count, name -Descending
get-command -CommandType cmdlet | Group-Object -Property verb | Sort-Object Count -Descending | Sort-Object name
get-command -CommandType cmdlet | Group-Object -Property verb | Sort-Object Count -Descending,  name

请通过 PS 中的单个查询帮助我

【问题讨论】:

  • 我不确定我是否遵循您的逻辑。你怎么能同时通过 2 个不同的属性对任何东西进行排序?
  • @Mosheperez 容易吗?首先,您按第一个属性排序,然后对于基于第一个具有相同排序顺序的每个项目,您按第二个属性排序,依此类推。

标签: powershell


【解决方案1】:

您可以通过提供带有 Descending 项的哈希表来覆盖单个属性的顺序:

Get-Command -CommandType cmdlet |Group-Object Verb |Sort-Object Count,@{Expression='Name';Descending=$false} -Descending

【讨论】:

    猜你喜欢
    • 2012-04-07
    • 1970-01-01
    • 1970-01-01
    • 2020-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-08
    相关资源
    最近更新 更多