1 Reply Latest reply on Mar 20, 2018 9:34 AM by jeanatwdh

    how to get host memory used per vm?

    jeanatwdh Lurker

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

        • 1. Re: how to get host memory used per vm?
          LucD Guru
          Community WarriorsvExpertUser Moderators

          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: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz