Compact/Shrink an Expandable/Dynamic VHD to fully recover space

Not sure if you are using Windows 7 Virtual PC or Windows Server 2008 R2 Hyper-V or Windows Server 2012 Hyper-V, but I will address each scenario to be safe.

  1. If you are using Windows 7, then you will want to mount the precompactor.iso (found in Program Files (x86)\Windows Virtual PC\Integration Components) and run precompact.exe from the mounted ISO. After this completes, you can shutdown the Virtual Machine and edit the VHD to compact the size. This should reduce the size close to the 25 GB of actual used space.

  2. If you are running Windows Server 2008 or 2008 R2 Hyper-V, I would recommend that you grab the precompactor.iso file from your Windows 7 computer and follow the same directions I provided in step 1 for Windows 7.

  3. If you are running Windows Server 2012 Hyper-V, then convert the VHD to VHDX and Windows Server 2012 Hyper-V will automatically shrink the size of the file based on actual usage.