Automation

 View Only
  • 1.  Get VMHost which has more CPU and Memory

    Posted Aug 18, 2022 03:29 PM

    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



  • 2.  RE: Get VMHost which has more CPU and Memory
    Best Answer

    Posted Aug 18, 2022 03:54 PM

    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


  • 3.  RE: Get VMHost which has more CPU and Memory

    Posted Aug 18, 2022 04:32 PM

    Perfect...That worked

    Thanks a lot