14387 shaares
5333 private links
5333 private links
You can compact using GUI tools, but PowerShell provides the complete method. Remember two things:
- You cannot compact a VHDX connected to a running virtual machine.
- The computer system that runs the Optimize-VHD cmdlet must have the complete Hyper-V role installed. The PowerShell module alone does not contain the necessary system services. If you must run the compact operation on a system that does not have Hyper-V, you can use diskpart instead.
The process centers around the Optimize-VHD cmdlet. In general, you’ll want to mount the VHDX into the management operating system to get the best results. For example:
Mount-VHD .dyndisk.vhdx -ReadOnly
Optimize-VHD .dyndisk.vhdx -Mode Full
Dismount-VHD .dyndisk.vhdx
Be aware that even for very small files, that can take some time to complete. The amount of time depends mostly on your available CPU cycle and the speed of your disk subsystem.