例如,我有一个变量,它用几个数组返回行:
@{sourceDSAcn=B; LastSyncResult=0} @{sourceDSAcn=A; LastSyncResult=9} @{sourceDSAcn=C; LastSyncResult=0} @{sourceDSAcn=M; Last SyncResult=10}我想按参数之一按字母顺序排列这一行。在这种情况下- by sourceDSAcn,所以结果必须是这样的:
@{sourceDSAcn=A; LastSyncResult=9} @{sourceDSAcn=B; LastSyncResult=0} @{sourceDSAcn=C; LastSyncResult=0} @{sourceDSAcn=M; Last SyncResult=10}我怎么能这么做?
发布于 2020-08-03 22:30:00
您的输出格式说明了两点:
[pscustomobject]实例).您已经使用this answer). cmdet将这些对象打印到主机(显示),从而在您的问题中显示出类似哈希表的类文字表示(请参阅this answer).)。
- If, instead, you want the usual rich display formatting you get by default - while still sending the output to the _host_ only rather than to the _success output stream_ - you can use the [`Out-Host`](https://learn.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Core/Out-Host) cmdlet.
- Conversely, to produce _data_ output to the _pipeline_, use either the [`Write-Output`](https://learn.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Utility/Write-Output) cmdlet or, preferably, PowerShell's implicit output feature, as shown below; for more information, see [this answer](https://stackoverflow.com/a/60534138/45375).为了按给定属性对(自定义)对象进行排序,只需将该属性的名称传递给
Sort-Object的(位置隐含的) -Property参数,正如Mathias R. Jessen有用的建议:
# Using $variable by itself implicitly sends its value through the pipeline.
# It is equivalent to: Write-Output $variable | ...
$variable | Sort-Object sourceDSAcn # same as: ... | Sort-Object -Property sourceDSAcnhttps://stackoverflow.com/questions/63235776
复制相似问题