4 Replies Latest reply on Feb 24, 2020 1:46 PM by LucD

    Connect Hard Disk Info with Guest disk information

    wtfham Lurker

      Looking for a way to get the hardisk item connected to the guest disk.  I would like to get a working solution to connect the harddisk info to the guest disk drive so I can set up automation to increase the hard disk size when the guest drive is out of space.   I started with a report from a different thread here that gets much of the info, but I can't see a way to get the free space of a particular disk lined up with its corresponding vmware harddisk item.  the $row.FreeSpaceGb item returns the freespace for all guest drives, as expected.....

      $vm = "hhs0532"

      $report = @()

      foreach($vms in $vm ){

          $gvm = (VMware.VimAutomation.Core\Get-VM $vms)

          Get-HardDisk -VM $vm | ForEach-Object {

              $HardDisk = $_

              $row = "" | Select VM, GuestName, Datastore, VMXpath, HardDisk, CapacityGB, FreeSpaceGb

                          $row.VM = $GVM.Name

                          $row.GuestName = $gvm.Guest.HostName

                          $row.Datastore = $HardDisk.Filename.Split("]")[0].TrimStart("[")

                          $row.VMXpath = $HardDisk.FileName

                          $row.HardDisk = $HardDisk.Name

                          $row.CapacityGB = ("{0:f1}" -f ($HardDisk.CapacityKB/1MB))

                          $row.FreeSpaceGb = ($gvm.Guest.Disks.freeSpaceGb)

                          #$row.DiskUsage = ($vmg.disks | select FreeSpaceGb)

                          $report += $row

         }

       

      }

      $report | ft -AutoSize

        • 1. Re: Connect Hard Disk Info with Guest disk information
          wtfham Lurker

          to clarify:  I want to monitor the free space on the guest drive, then increase the corresponding vm disk when the free space is down to say 5%.  Am working now just to be able to connect the 2 disparate disk objects(vm harddisk, and guest disk). 

          • 2. Re: Connect Hard Disk Info with Guest disk information
            LucD Guru
            Community WarriorsvExpertUser Moderators

            I'm not sure if you searched in this community for similar questions, but this a kind of Holy Grail.

            And not to raise your expectations, there is no fool-proof way of doing that.

             

            There are some solutions which work in very specific conditions.

            For example, a specific guest OS, only 1 guest OS partition per VMDK,  using VMDK of different sizes...

            But there is, for the moment, no solution that works in all circumstances.

            Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
            • 3. Re: Connect Hard Disk Info with Guest disk information
              wtfham Lurker

              i did search....   hence the starting point, and I think you might have been involved in that discussion too.  The machines I want to do this with all meet some criteria or another...   Typically one partition for VMDK for instance.  However they oftern have 2 disks of the same size ... making a compare very harrd(if not impossible) to do. 

              • 4. Re: Connect Hard Disk Info with Guest disk information
                LucD Guru
                User ModeratorsCommunity WarriorsvExpert

                The type of Guest OS also plays a role.

                 

                A Windows-based OS (not all versions) might be a bit simpler in some cases.

                But there are many factors that can play a role (MBR or GPT, simple/striped/spanned/mirrored/RAID-5 volume, system/recovery/data partition or free space, encrypted...)

                 

                If you have a 1 partition/1 VMDK partition layout you might try with the PCI slot number.
                But the allocation mechanism on the VMware side is still a mystery to me.
                So if VMDK have been removed/added to a VM, that trick most probably will not work.


                On the Linux side the use of an LVM is most of the time masking all links between a guest OS filesystem and a VMDK.

                Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz