2

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

LightningWar
  • 915
  • 1
  • 19
  • 35
  • `Get-VMHost | Get-VM | Get-Stat -CPU -Memory -Realtime` maybe? (from the [vSphere PowerCLI Reference](https://pubs.vmware.com/vsphere-51/index.jsp?topic=%2Fcom.vmware.powercli.cmdletref.doc%2FGet-Stat.html) – Theo Sep 07 '18 at 17:45

1 Answers1

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:

  • cpu.usage.average
  • cpu.usagemhz.average
  • cpu.ready.summation

(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
Kyle Ruddy
  • 1,886
  • 1
  • 7
  • 5