Looking for Wasted Space inside Virtual Machines

Recently, I tried to update the operating system installed inside of one of my virtual machines.  I quickly received an error message stating that I did not have enough free space available to perform the upgrade.  My immediate thought was that I would need to expand the size of the virtual hard disk – but after a bit of investigation I was surprised to discover that the virtual hard disk had already been expanded.  I just hadn’t expanded the partition to take advantage of it.

Clearly, I had been planning to do this at some other time – and had gotten distracted in the middle of the process.

This made me wonder: do I have any other virtual machines that are sitting on unpartitioned, wasted space?

Luckily, this is an easy question to answer.  You see, the virtual hard disk object that is returned by “Get-VHD” includes a “MinimumSize” property.  This property will tell you how much unpartitioned space is available at the end of the disk.  So the following command:

Get-VM | Get-VMHardDiskDrive | Get-VHD | Select path, @{Name="Free Space (GB)";Expression={"{0:N2}" -f (($_.Size - $_.MinimumSize)/1GB)}}

Will tell you exactly what is going on with your system.  When I ran this on my server:

image

I discovered that I had two extra virtual machines with wasted space!

Cheers,
Ben