VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Get VMHost which has more CPU and Memory

Hi,

I am using the below script to get the VMhost name which has less CPU and Memory used. How can I get the VMHost name which has minimum 30% of free CPU and 30% free Memory of the total capacity of the VMHost.

Get-Cluster MyClust | Get-VMHost |
where{$_.PowerState -eq 'PoweredOn'} |
Sort-Object -Property CpuUsageMhz, MemoryUsageGB |
Select-Object -First 1 -ExpandProperty Name

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Something like this?

Get-Cluster cluster | Get-VMHost |
Where-Object { $_.PowerState -eq 'PoweredOn' } |
Select-Object Name,
  @{N = 'CpuFree'; E = { 1 - $_.CpuUsageMhz/$_.CpuTotalMhz}},
  @{N = 'MemFree'; E = { 1 - $_.MemoryUsageGB/$_.MemoryTotalGb}} |
  where{$_.CpuFree -ge 0.3 -and $_.MemFree -ge 0.3} |
Sort-Object -Property CpuFree,Memfree -Descending |
Select-Object -First 1 -Property Name


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Something like this?

Get-Cluster cluster | Get-VMHost |
Where-Object { $_.PowerState -eq 'PoweredOn' } |
Select-Object Name,
  @{N = 'CpuFree'; E = { 1 - $_.CpuUsageMhz/$_.CpuTotalMhz}},
  @{N = 'MemFree'; E = { 1 - $_.MemoryUsageGB/$_.MemoryTotalGb}} |
  where{$_.CpuFree -ge 0.3 -and $_.MemFree -ge 0.3} |
Sort-Object -Property CpuFree,Memfree -Descending |
Select-Object -First 1 -Property Name


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Perfect...That worked 🙂

Thanks a lot

0 Kudos