How to Merge Hyper-V Snapshots With Powershell
1 min read
August 25, 2023
158 words
Identify your child avhdx file
Get-VM | Get-VMHardDiskDrive | Select VMName,Path
VMName Path
------ ----
Domain Controller D:\VMs\Domain Controller_1023082130.avhdx
Installing the Hyper-V Powershell CMDLETS
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Management-PowerShell
Merge the AVHDX
Make sure your VM is turned off. The Merge-VHD operation requires the avhdx file be offline.
The destination path will be the snapshot or VHDX file that you want to merge into. This will automatically merge any of the parent snapshots in between the one you're using and the one you're merging into.
So if you're merging from the fifth snapshot into the first snapshot, it'll merge the fifth into the fourth, the fourth into the third, the third into the second, and the second into the first.
Merge-VHD -Path "D:\VMs\Domain Controller_1023082130.avhdx" -DestinationPath "D:\VMs\Domain Controller.vhdx"y
Set VM Drive
Merging the snapshot deletes the snapshot after. Update the drive path of your VM to the snapshot you merged into
Set-VMHardDiskDrive -VMName "Domain Controller" -Path "D:\VMs\Domain Controller.vhdx" -ControllerType SCSI