VMware Cloud Community
AlexP012
Contributor
Contributor

Return Host CPU value

Hi

I want to identify the VM's that are using the most host cpu at the point at which the script is run.

Does anyone know how I reeturn this value?

0 Kudos
3 Replies
AlexP012
Contributor
Contributor

This is the value I want

0 Kudos
LucD
Leadership
Leadership

You could do something like this.

Note that this will return the latest measurement from a 20 second interval.

The values you see in the Web Client are an average over a somewhat longer time period.

So the values might differ slightly.

$vms = Get-VM

Get-Stat -Entity $vms -Stat cpu.usagemhz.average -Realtime -MaxSamples 1 -Instance '' -ErrorAction SilentlyContinue |

Select @{N='VM';E={$_.Entity.Name}},@{N='CPUMhz';E={$_.Value}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
AlexP012
Contributor
Contributor

Thanks for that Luc, that was just what I was looking for.

I tweaked it a bit to

$vms = Get-VM| Where-Object {$_.powerstate -eq 'PoweredOn'}

Get-Stat -Entity $vms -Stat cpu.usagemhz.average -Realtime -MaxSamples 1 -Instance '' -ErrorAction SilentlyContinue | sort-object {[int]$_.value} -descending | Select @{N='VM';E={$_.Entity.Name}},@{N='CPUMhz';E={$_.Value}} -first 10

 
$vms = Get-VM| Where-Object {$_.powerstate -eq 'PoweredOn'}
Get-Stat -Entity $vms -Stat cpu.usagemhz.average -Realtime -MaxSamples 1 -Instance '' -ErrorAction SilentlyContinue | sort-object {[int]$_.value} -descending | Select @{N='VM';E={$_.Entity.Name}},@{N='CPUMhz';E={$_.Value}} -first 10
0 Kudos