VM disk space details using powercli

VM disk space details using powercli


If the VMs have VMware tools installed, you can read the free space of the partitions on the OS side with Get-VMGuest like:
PS D:\> (Get-VM MyVM | Get-VMGuest).Disks

CapacityGB      FreeSpaceGB     Path
----------      -----------     ----
29,483          10,998          C:\
9,967           5,845           F:\
9,967           8,552           D:\
9,967           9,371           E:\

The problem is that this only lists formatted partitions, and you can't directly correlate a certain OS partition to a certain virtual disk without adding some substantial logic that would probably involve executing commands inside the Guest OS with Invoke-VMScript to be reliable. It gets even more complicated if there are multiple partitions on the same disk, or there is unpartitioned/unformatted disk space.

The following snippet will output the total free space of all partitions combined (which will be repeated per disk):
Get-VM | ForEach {
  $vm = $_
  Get-harddisk -VM $_ | Select-Object -Property Parent, Name, StorageFormat, CapacityGB,
    @{N='OS Total Free Space GB of all partitions combined'; E={ [math]::round((Get-VMGuest $vm | ForEach-Object { ($_.Disks) } | Measure-Object -property FreeSpaceGB -sum).Sum)}}
} | Format-Table -Autosize


Parent         Name       StorageFormat CapacityGB OS Total Free Space GB of all disks combined
------         ----       ------------- ---------- --------------------------------------------
VM1            Hard disk 1        Thick     30                                       24
VM1            Hard disk 2        Thick     10                                       24
VM2            Hard disk 1         Thin     30                                       35
VM2            Hard disk 2 EagerZeroedThick     10                                       3535

Comments

Popular posts from this blog

Using Non-Maskable Interrupt (NMI) facilities to troubleshoot unresponsive VMware Virtual Machine.

Removing invalid linked clone entries automatically using the ViewDBChk tool

VMTool update steps on Horizon VDI Parent VM