2 Replies Latest reply on Sep 30, 2019 5:46 AM by ganapa2000

    Find the host with most memory free space.

    ganapa2000 Hot Shot

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

        • 1. Re: Find the host with most memory free space.
          LucD Guru
          User ModeratorsCommunity WarriorsvExpert

          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: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: Find the host with most memory free space.
            ganapa2000 Hot Shot

            perfect LucD.

             

            Thank you very much