On the vSphere client host summary page, current CPU usage stats are displayed:
CPU Free: 76.38 GHz
Used: 4.02 GHz Capacity: 80.4 GHz
I am trying to retrieve this information using PowerCLI
, so far I have discovered this property:
$vmhost = Get-VMHost
$vmhost.ExtensionData.Summary.Hardware
This property displays CPU information including model, cores, threads etc. but not current usage as a percentage.
Is this possible using PowerCLI
?
PowerCLI version: 6.5 PowerShell version: 5.1
To do this, you'll want to get comfortable with Get-Stat
There are 3 stat types that you can reference for CPU stats:
(Other stat types can be found using Get-StatType
)
You can pull the stats with the following:
$vmhost | Get-Stat -Stat cpu.usagemhz.average
However, if you just want the most current value:
$vmhost | Get-Stat -Stat cpu.usagemhz.average -Realtime -MaxSamples 1