PowerShell Get-Counter 命令,-ComputerName 与 -Counter

PowerShell Get-Counter command, -ComputerName vs -Counter

调用Get-Counter时使用-Co​​mputerName参数和使用-Co​​unter参数中的路径有区别吗?

Get-Counter -Counter "\Memory\Available MBytes" -ComputerName \serv01 
Get-Counter -Counter "\serv01\Memory\Available MBytes"

选择一个而不是另一个的原因是什么?

看起来通过使用 -ComputerName 参数,您可以在一条命令中从多台计算机的性能计数器获取数据,而通过在计数器路径中指定服务器名称,您需要使用循环或多个不同的命令。

示例5:从多台计算机获取特定计数器数据

The first command saves the **Disk Reads/sec** counter path in the $DiskReads variable.
PS C:\> $DiskReads = "\LogicalDisk(C:)\Disk Reads/sec"

The second command uses a pipeline operator (|) to send the counter path in the $DiskReads variable to the **Get-Counter** cmdlet. The command uses the **MaxSamples** parameter to limit the output to 10 samples.
PS C:\> $DiskReads | Get-Counter -Computer Server01, Server02 -MaxSamples 10
Get-Counter -Counter "\Memory\Available MBytes" -ComputerName \serv01 

这是一个通用命令,您通常知道您指的是哪个计数器,并且可能知道或不知道 location.If 在不同位置有多个同名计数器,这将 return 所有 them.And 您也可以通过管道将计算机名称中的多个服务器传输到所有这些服务器上的计数器。

Get-Counter -Counter "\serv01\Memory\Available MBytes"

这是针对特定实例的,其中只有一个柜台,在特定位置,您知道。