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

时间:2017-06-23 18:24:08

标签: powershell performancecounter

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

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

选择其中一个的原因是什么?

2 个答案:

答案 0 :(得分:1)

通过使用-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

答案 1 :(得分:0)

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

这是一个通用命令,你通常知道你指的是什么计数器,可能知道或者不知道位置。如果在不同的位置有多个同名的计数器,这将返回所有这些并且你也可以在计算机名中管道多个服务器来获取所有这些服务器上的计数器。

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

这是针对特定实例的,其中只有一个计数器并且在特定位置并且您知道它。

相关问题