Hyper-V

Reclaim Unused Space in Hyper-V

September 18, 2025 Rich 1 min read

Overview

This guide explains how to reclaim unused disk space from a Hyper-V virtual machine (VM) after cleaning it up internally. The process involves zeroing out free space inside the VM and then compacting the virtual hard disk (VHDX) file from the host.

Step-by-Step Instructions

1. Zero Free Space Inside the VM

On the guest VM, download and run SDelete from Microsoft Sysinternals:
https://learn.microsoft.com/en-us/sysinternals/downloads/sdelete

Open a Command Prompt as Administrator and run:

sdelete -z c:

This process may take a significant amount of time, depending on the size of the disk and the amount of free space.

2. Shut Down the VM

After sdelete completes, gracefully shut down the VM from within the guest OS or via the Hyper-V Manager.

3. Compact the VHDX File

On the Hyper-V host, open PowerShell as Administrator and run:

Optimize-VHD -Path "E:\Hyper-V\Disks\VM.vhdx" -Mode Full

Replace "E:\Hyper-V\Disks\VM.vhdx" with the full path to your actual VHDX file.

Notes

  • This process is safe but should be done during a maintenance window as it involves downtime.
  • The -Mode Full parameter provides the most compact result by zeroing and trimming blocks.

Leave a comment