VMware Cloud Community
Bean78
Contributor
Contributor

PCLI script to determine the virtual machine disk space usage

I have a script to identify the number of vHDD attached to a virtual machine and to determine its capapcity. Can anyone guide me with a script to determine the vHDD usage (For example if a VM is assigned with 50GB of vHDD how to determine its used space for all the VM's in a vCenter console)

$report = @()

foreach ($vm in Get-VM)

{

   $row = "" | Select Name, HD1, HD2

   $row.Name = $vm.Name

   $row.HD1 = (Get-HardDisk -VM $vm -Name 'Hard disk 1' -ErrorAction SilentlyContinue).CapacityGB

   $row.HD2 = (Get-HardDisk -VM $vm -Name 'Hard disk 2' -ErrorAction SilentlyContinue).CapacityGB

   $report += $row

}

$report | Export-Csv ".\report.csv" -NoTypeInformation -UseCulture

0 Kudos
1 Reply
LucD
Leadership
Leadership

To see the usage of a VMDK, this will only have meaning in the case of Thin disks, you can have a look at my Yadr - A vdisk reporter post.

If you mean to find the usage inside the guest OS, I'm afraid there is currently no foolproof method to link guest OS partitions to VMDK.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos