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
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
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
Perfect...That worked 🙂
Thanks a lot