VMware Cloud Community
wtfham
Contributor
Contributor

Connect Hard Disk Info with Guest disk information

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

Reply
0 Kudos
4 Replies
wtfham
Contributor
Contributor

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). 

Reply
0 Kudos
LucD
Leadership
Leadership

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
wtfham
Contributor
Contributor

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. 

Reply
0 Kudos
LucD
Leadership
Leadership

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos