Merging VHD

Last night I had to troubleshoot a low free space alert on a cluster. While everything looked normal and no Checkpoints or backups of Virtual Machines were on the Clustered Shared Volume a problem with the backup software flew under the radar and created a massive problem! There was an offending VM that was backed up normally and no checkpoints existed but it’s VHD files were differencing disks. A situation most of the IT Pro’s out there are familiar with.

So how do you rectify this? This VM had grown to a TB of data and while no checkpoints existed it had over 300 differencing VHD files. Restoring such a VM would take hours so that’s not a great option. Well I first started with copying over the XML configuration files of the virtual machine and importing this VM again with NO-VHD drives on it. So far so good we have a working VM with the same GUID and the same network adapters but with no drives.

{Powershell} to the rescue!

Powershell is capable of doing amazing things so I wrote this little script that actually gets each drive and then merges all of the VHD files into the parent so that you can attach it again on the virtual machine. Enjoy!