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?
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.
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
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