如何合并两个几乎相同的 powershell 命令的输出?

Chr*_*ski 5 powershell

我正在监视每个 CAS 服务器的连接计数,并希望连接每个服务器的输出,以便可以清晰地显示它。

我尝试过“添加”结果,如 $rpc = $rpc + XXXCommandHereXXX,并按如下所示进行管道传输,但我无法“加入”命令。

 $rpc = (get-counter -ComputerName NYCEXCAS01 -Counter "RPC/HTTP Proxy\Current Number of Incoming RPC over HTTP Connections").countersamples  | Select-Object Path, CookedValue 
 $rpc | (get-counter -ComputerName NYCEXCAS02 -Counter "RPC/HTTP Proxy\Current Number of Incoming RPC over HTTP Connections").countersamples  | Select-Object Path, CookedValue 
Run Code Online (Sandbox Code Playgroud)

我是否试图做一些逻辑上不合理的事情?

jsc*_*ott 4

不要Select-Object对每个执行Get。然后,您应该可以毫无问题地“添加”集合并Select稍后获取所需的属性:

$a = (get-counter -ComputerName NYCEXCAS01 -Counter "RPC/HTTP Proxy\Current Number of Incoming RPC over HTTP Connections").countersamples
$b = (get-counter -ComputerName NYCEXCAS02 -Counter "RPC/HTTP Proxy\Current Number of Incoming RPC over HTTP Connections").countersamples
$rpc = $a + $b
$rpc | Select-Object -Property Path, CookedValue 
Run Code Online (Sandbox Code Playgroud)

您也可以只收集所有Get-Counter结果,然后 Select收集 s CounterSample,然后执行Selectfor Path, CookedValue