Compact a VHD disk in Hyper-V

I have a lab environment with System Center using Hyper-V on my Windows 8 laptop. This is how I compact the virtual disks using powershell when they get too big.

  1. Mount-Vhd –path <full path the vhd file> -readonly
  2. Optimize-Vhd -path <full path the vhd file> -Mode Full
  3. Dismount-vhd -path <full path the vhd file>

Sometimes I have to run the optimize-vhd command a few times before it actually optimizes it, this seems to be a bug. You can automate this by scheduling it as a task and never worry about it again.

Anders Rødland

Anders Rødland started his IT career in 2006. My main focus is MS Configuration Manager and client management, and I currently hold active 15 Microsoft certifications. Certified on Windows Server, Windows Client, SQL, Exchange and System Center Configuration Manager. Anders Rødland also holds an ITIL Foundation certification.This is my private blog and do not represent my employer. I use this to share information that I find useful. Sharing is caring.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.