As you know, I have been using Hyper-V since before it was released, and am a huge proponent of the solution (although I am also a huge proponent of VMware). The fact that Hyper-V is also included in Windows 10 makes my life easier – I use it on my Windows Client for several reasons. In fact, at present I have four virtual machines on my Surface Pro 4, two of which I use on a very regular basis.
So when I notice from time to time that my C: drive is running out of space, I know immediately what the culprit is… my dynamically expanding drives have, in a word, expanded.
Not good… I need more than 3.18GB free space to be comfortable. However when I look at the drives, I know that none of them are overly taxed… the VM I use most often (I use it to download files that I am not sure are safe so that I can ‘Sandbox’ them) is a dynamically expanding virtual disk that is as much as 80GB, but only 31GB is used.
That should be very comfortable… and yet there we see the usage.
A 53GB vhdx file for about 31GB of information. It is easily explained of course… With a dynamically-expanding virtual hard disk the file gets bigger when you write to it, but when you then delete files and clean it up the file does not get smaller… or at least not automatically. So what you have to do is this:
At this point the process will begin, and when it is done you should be good to go.
Yes, I know… you can do everything you want in the wizard… but let’s try a quick PowerShell cmdlet anyways
Optimize-VHD -Path C:\Hyper-V\Sandbox-PC\Sandbox-PC.vhdx -ComputerName MDG-SP4
It only took a couple of minutes, and here are the results:
Almost 10GB freed up. That makes life so much more comfortable. Of course, since I use that virtual PC for these purposes a lot, I will want to keep an eye out for this creep and perform this script on a regular basis. Hence why you might want to use PowerShell over the GUI.