What it does
Hyper-V only compacts blocks it recognizes as unused or entirely zeroed, and a VHDX is organized in blocks of usually 32 MB: a single “dirty” byte is enough for the whole block to remain allocated.
ShrinkPreparation optimizes the drive, consolidates free space, zeroes unused space and tells the virtual disk which areas are free. When it finishes, it generates a PowerShell script for the host that shuts down the VM, compacts its dynamic disks, shows the space reclaimed and, if you wish, restarts it.
- Operations of your choiceOptimization, free space consolidation, zero-fill and retrim.
- All fixed drivesProcessed one after the other, if you ask it to.
- Environment analysisPrivileges, VM and host name, TRIM, shadow copies, BitLocker, hibernation.
- Clear progressBytes written, speed and estimated time remaining.
- Script for the hostGenerated automatically, saved to file and copyable to the clipboard.
- Safe to interruptAlways cleans up temporary files and detects leftovers from an interrupted run.
Requirements
| In the VM | Windows 10/11 or Windows Server 2016 and later, .NET Framework 4.8, administrator account |
|---|---|
| On the host | Hyper-V role with the Hyper-V PowerShell module |
| Virtual disk | Dynamic VHDX or VHD (fixed-size disks cannot be compacted) |
| Checkpoints | None: with checkpoints the base disk cannot be compacted |
Installation
- On the host, check the free space on the VHDX volume and delete the VM's checkpoints.
- Copy ShrinkPreparation into the VM and run it as administrator.
- Choose drives and operations, then start the procedure.
- When it finishes, run the generated PowerShell script on the host: it compacts the disk with the VM shut down.
All the details are in the manual, which you can download alongside.
Before you start
- Zero-fill temporarily fills the disk: the .vhdx file can grow up to its maximum size. Check the space on the host first.
- The program does not compact the VHDX from inside the VM: compaction is always done on the host, with the VM shut down.
- Back up the VM before proceeding.