Get and repair VHD Fragmentation on Hyper-V with PowerShell

Hello,

From your Hyper-V host, you can see how much your VHDs are fragemented :

Get-VM | Get-VMHardDiskDrive | Get-VHD | Select-Object Path,VhdFormat,VhdType,FragmentationPercentage

VM-VHD-Fragmentation-1

If you want to defragment them, you an use Optimize-VHD or you can Live Storage Migration :

Optimize-VHD -Path "C:VMClient1Virtual Hard DisksClient1.vhdx"
Move-VMStorage -VMName Client1 -DestinationStoragePath D:VM

Leave a Reply