VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Find the host with most memory free space.

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"}

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I don't think there is a MemoryFreeGB property, but there are MemoryTotalGB and MemoryUsageGB properties.

Try doing

$vmhowime = 200

$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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

I don't think there is a MemoryFreeGB property, but there are MemoryTotalGB and MemoryUsageGB properties.

Try doing

$vmhowime = 200

$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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

perfect LucD.

Thank you very much Smiley Happy

0 Kudos