VMware Cloud Community
jeanatwdh
Contributor
Contributor

how to get host memory used per vm?

I found the commands to get allocated memory and cpu per vm but would like to collect what each vm is actually using. 

0 Kudos
1 Reply
LucD
Leadership
Leadership

You could do something like this

$vms = Get-VM | where{$_.PowerState -eq 'PoweredOn'}

Get-Stat -Entity $vms -Stat 'mem.consumed.average','cpu.usage.average' -Realtime -MaxSamples 1 |

Group-Object -Property {$_.Entity.Name} | %{

    New-Object PSObject -Property @{

        VM = $_.Name

        CPUPerc = $_.Group | where{$_.MetricId -eq 'cpu.usage.average'} | select -ExpandProperty Value

        MemoryMB = [math]::Round(($_.Group | where{$_.MetricId -eq 'mem.consumed.average'} | select -ExpandProperty Value)/1MB,1)

    }

}


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

0 Kudos