Hi,
I am looking to find out the host with most memory free space.
How can I get it. I tried the below script, but I returns blank result
Please help
$vmhowime = 200
$vmh = get-vmhost | Sort-Object -Property MemoryFreeGB -Descending:$true | Select-Object -First 1
if (($vmh.MemoryFreeGB + 20) -gt $vmhowime) {Get-vm} else {"oh, no -- not enough freememory on host '$($vmh.Name)' to provision new VM"}
I don't think there is a MemoryFreeGB property, but there are MemoryTotalGB and MemoryUsageGB properties.
Try doing
$vmh = Get-VMHost | Sort-Object -Property {$_.MemoryTotalGB - $_.MemoryUsageGB} -Descending:$true | Select-Object -First 1
if (($vmh.MemoryTotalGB - $vmh.MemoryUsageGB + 20) -gt $vmhowime) {
Get-VM -Location $vmh
}
else {
"oh, no -- not enough freememory on host '$($vmh.Name)' to provision new VM"
}
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I don't think there is a MemoryFreeGB property, but there are MemoryTotalGB and MemoryUsageGB properties.
Try doing
$vmh = Get-VMHost | Sort-Object -Property {$_.MemoryTotalGB - $_.MemoryUsageGB} -Descending:$true | Select-Object -First 1
if (($vmh.MemoryTotalGB - $vmh.MemoryUsageGB + 20) -gt $vmhowime) {
Get-VM -Location $vmh
}
else {
"oh, no -- not enough freememory on host '$($vmh.Name)' to provision new VM"
}
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
perfect LucD.
Thank you very much