如何在Powershell中将两个Note属性合并在一起?
以下查询返回实例列表,但我想合并“注释属性”,如下所示。
$((Get-Counter '\Process(Chrome*)\ID Process' -ErrorAction SilentlyContinue).CounterSamples | % {[regex]$a = "^.*\($([regex]::Escape($_.InstanceName))(.*)\).*$";[PSCustomObject]@{InstanceName=$_.InstanceName;InstanceId=$a.Matches($($_.Path)).groups[1].value}})
查询的输出是:InstanceName InstanceId
------------ ----------
Chrome #2
Chrome #1
Chrome
但是我希望输出是这样的。InstanceName
------------
Chrome#2
Chrome#1
Chrome
最佳答案
您只需要将第一个属性的表达式值更改为:
@{InstanceName="$($_.InstanceName)$($a.Matches($($_.Path)).groups[1].value)"}})
在全:(Get-Counter '\Process(Chrome*)\ID Process' -ErrorAction SilentlyContinue).CounterSamples | % {[regex]$a = "^.*\($([regex]::Escape($_.InstanceName))(.*)\).*$";[PSCustomObject]@{InstanceName="$($_.InstanceName)$($a.Matches($($_.Path)).groups[1].value)"}}
关于powershell - Powershell-合并两个Note属性,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/63225223/