Note: This post was originally written on January 9, 2016, and updated on November 26, 2026, to cover SSD/NVMe TRIM handling, modern Hyper-V PowerShell syntax, and safer back-out steps.
Years ago, I walked into a client site and found a Hyper-V host with 7 TB of dynamically expanding .vhd disks provisioned on a server that only had 1.2 TB of physical storage. When a dynamically expanding disk fills up and runs the host out of space, every virtual machine (VM) on that host slams into a paused state. That is why I prefer fixed-size VHDX disks for production servers, or at least keeping virtual disk sizes realistic.
If you inherit an over-provisioned VM or need to reclaim wasted space on a Hyper-V host, you can shrink the virtual disk down to size. You just have to shrink the partition inside the disk before Hyper-V will let you shrink the disk file itself.
Prerequisites
Before you touch the virtual disk, make sure you have:
- The target VM shut down cleanly (not saved or paused), with no active Hyper-V checkpoints/snapshots attached.
- A full backup of the VM or a copy of the .vhd/.vhdx file stored somewhere safe as a back-out plan.
- The Hyper-V PowerShell module installed on the host (included with the Hyper-V role) and an elevated PowerShell window.
Optimizing and Shrinking the Volume
- On the Hyper-V host, double-click the .vhd or .vhdx file (or right-click and select Mount) so Windows mounts its partitions with drive letters. (If the file is in use, make sure the VM is powered off.)
- If the host is running on SSDs or NVMe, do not run a traditional defrag. Instead, run a ReTrim so Hyper-V knows which blocks are actually free. Run this in an elevated PowerShell prompt, replacing E with the mounted drive letter (if your host is still on spinning hard drives, run Optimize-Volume -DriveLetter E -Defrag -Verbose instead):
Optimize-Volume -DriveLetter E -ReTrim -Verbose
Code language: PowerShell (powershell)
- Open Disk Management (diskmgmt.msc), right-click the mounted VM partition, and select Shrink Volume.
- Subtract about 1,000 MB from the maximum available shrink space and enter that number, then click Shrink. Leaving a small buffer helps prevent Windows from throwing free-space errors during the shrink.
- Once the partition finishes shrinking and you see unallocated space at the end of the disk, right-click the disk label on the left in Disk Management and select Eject (or dismount it via PowerShell) so the file is unlocked.
Warning: Never skip dismounting the virtual disk before running Convert-VHD or Resize-VHD. If the host still has the disk mounted, PowerShell will fail with a file-in-use error.
Converting and Shrinking the Virtual Disk
Resize-VHD only works on .vhdx files, not legacy .vhd files. If you are starting with an older .vhd, convert it to .vhdx first. Using -VHDType Dynamic keeps the intermediate file small, and keeping the original .vhd untouched gives you an instant rollback if anything goes wrong.
Convert-VHD `
-Path "D:\VMs\Server01\sourceDisk.vhd" `
-DestinationPath "D:\VMs\Server01\convertedDisk.vhdx" `
-VHDType Dynamic
Code language: PowerShell (powershell)
Now shrink the .vhdx down to your target size (or use -ToMinimumSize to snap it right down to the end of the shrunk partition).
Resize-VHD `
-Path "D:\VMs\Server01\convertedDisk.vhdx" `
-SizeBytes 120GB
Code language: PowerShell (powershell)
If this is a production VM and you want to prevent future over-provisioning, convert the resized disk to Fixed so it reserves its full 120 GB on the host up front. You can pass -DeleteSource here to clean up the intermediate convertedDisk.vhdx once the fixed disk is written.
Convert-VHD `
-Path "D:\VMs\Server01\convertedDisk.vhdx" `
-DestinationPath "D:\VMs\Server01\fixedDisk.vhdx" `
-VHDType Fixed `
-DeleteSource
Code language: PowerShell (powershell)
Attaching the Disk and Verifying
- In Hyper-V Manager, right-click the VM and open Settings.
- Select the Hard Drive under the SCSI or IDE controller, click Browse, and point it to fixedDisk.vhdx.
- Boot the VM and verify that Windows starts cleanly and your services are healthy.
- Open Disk Management inside the guest OS and extend the volume into any leftover unallocated space if needed.
- Once you confirm the VM is running normally, delete the original sourceDisk.vhd file to reclaim the space on the host.
Wrapping Up
Shrinking a Hyper-V virtual disk takes a few extra steps because you have to shrink the guest partition before Hyper-V will let you trim the .vhdx container. Keep your original disk file until the resized .vhdx boots cleanly, and you can reclaim wasted host storage without risking your VM.