从具有两个 CPU 的服务器在 PowerShell 中获取 CPU 平均值时出现问题
Problems getting CPU Average in PowerShell from a server with two CPU's
我正在尝试 运行 在具有两个物理 CPU 的远程计算机上执行以下操作,因此它 return 没有任何价值。
Get-WmiObject Win32_Processor -computername X |
Measure-Object -property LoadPercentage -Average |
Select-Object -ExpandProperty Average
(来源:How to Determine the Average CPU Percentage using a Powershell Command and Output the CPU Percentage as a Numeric Percentage with no Labels)
这是我 运行 Get-WmiObject Win32_Processor -computername X
:
时的输出
Caption : Intel64 Family 6 Model 63 Stepping 4
DeviceID : CPU0
Manufacturer : GenuineIntel
MaxClockSpeed : 2195
Name : Intel(R) Xeon(R) CPU E7-4850 v3 @ 2.20GHz
SocketDesignation : None
Caption : Intel64 Family 6 Model 63 Stepping 4
DeviceID : CPU1
Manufacturer : GenuineIntel
MaxClockSpeed : 2195
Name : Intel(R) Xeon(R) CPU E7-4850 v3 @ 2.20GHz
SocketDesignation : None
当我运行Get-WmiObject Win32_Processor -computername X | Measure-Object -property LoadPercentage -Average | Select-Object -ExpandProperty Average
:
时输出
0
这是我第一次 post 在这里。由于我尝试使用的代码来自 Stack Overflow,因此我决定在此处 post 而不是在服务器故障上。
编辑:我正在寻找一种方法来从正在查询的远程机器上的所有可用 cpu 中获取平均 cpu 负载,因此无论有多少 CPU的远程机器有。
我的解决方案是改用 invoke-command:
Invoke-Command -ComputerName X -Credential $creds {
Get-WmiObject Win32_Processor |
Measure-Object -property LoadPercentage -Average |
Select-Object -ExpandProperty Average
}
..虽然我实际上最终使用 Get-Counter 来获得 cpu 用法(它也有内置的样本和间隔参数):
Invoke-Command -ComputerName X -Credential $creds {
((Get-Counter -counter '\Processor(_Total)\% Processor Time').CounterSamples).CookedValue
}
我正在尝试 运行 在具有两个物理 CPU 的远程计算机上执行以下操作,因此它 return 没有任何价值。
Get-WmiObject Win32_Processor -computername X |
Measure-Object -property LoadPercentage -Average |
Select-Object -ExpandProperty Average
(来源:How to Determine the Average CPU Percentage using a Powershell Command and Output the CPU Percentage as a Numeric Percentage with no Labels)
这是我 运行 Get-WmiObject Win32_Processor -computername X
:
Caption : Intel64 Family 6 Model 63 Stepping 4
DeviceID : CPU0
Manufacturer : GenuineIntel
MaxClockSpeed : 2195
Name : Intel(R) Xeon(R) CPU E7-4850 v3 @ 2.20GHz
SocketDesignation : None
Caption : Intel64 Family 6 Model 63 Stepping 4
DeviceID : CPU1
Manufacturer : GenuineIntel
MaxClockSpeed : 2195
Name : Intel(R) Xeon(R) CPU E7-4850 v3 @ 2.20GHz
SocketDesignation : None
当我运行Get-WmiObject Win32_Processor -computername X | Measure-Object -property LoadPercentage -Average | Select-Object -ExpandProperty Average
:
0
这是我第一次 post 在这里。由于我尝试使用的代码来自 Stack Overflow,因此我决定在此处 post 而不是在服务器故障上。
编辑:我正在寻找一种方法来从正在查询的远程机器上的所有可用 cpu 中获取平均 cpu 负载,因此无论有多少 CPU的远程机器有。
我的解决方案是改用 invoke-command:
Invoke-Command -ComputerName X -Credential $creds {
Get-WmiObject Win32_Processor |
Measure-Object -property LoadPercentage -Average |
Select-Object -ExpandProperty Average
}
..虽然我实际上最终使用 Get-Counter 来获得 cpu 用法(它也有内置的样本和间隔参数):
Invoke-Command -ComputerName X -Credential $creds {
((Get-Counter -counter '\Processor(_Total)\% Processor Time').CounterSamples).CookedValue
}