Powershell script to merge Hyper-V Virtual Machine disks
In some situations you might find a VM disk to be part of a series of differencing disks. Take this example:
If this was the result of VM Checkpoints, the fix would be easy: simply delete the checkpoints which merges the disks. But his is not the case. Hyper-V Manager shows no checkpoints:
Powershell confirms (notice no output):
This script shuts down the VM and merges its disks. It uses the Get-ParentPath function.
This script can be downloaded from the Microsoft Script Center Repository.
To use this script, download it, run it as administrator, then use the function.
To see help:
NAME Merge-VMDisks SYNOPSIS Function to merge VM disks SYNTAX Merge-VMDisks [-VMName] [[-LogFile] ] [-WhatIf] [-Confirm]  DESCRIPTION Function/script to merge VM disks. The script will power down the VM in the process. PARAMETERS -VMName Name of the VM whose VHD(x) disks are to be merged Required? true Position? 1 Default value Accept pipeline input? true (ByValue, ByPropertyName) Accept wildcard characters? false -LogFile Name and path of the file where the script will log its steps and progress Required? false Position? 2 Default value ".\Merge-VMDisks_$(Get-Date -format yyyyMMdd_hhmmsstt).txt" Accept pipeline input? false Accept wildcard characters? false -WhatIf  Required? false Position? named Default value Accept pipeline input? false Accept wildcard characters? false -Confirm  Required? false Position? named Default value Accept pipeline input? false Accept wildcard characters? false This cmdlet supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer, PipelineVariable, and OutVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). NOTES Function by Sam Boutros v1.0 - 11/01/2014 -------------------------- EXAMPLE 1 -------------------------- C:\PS>Merge-VMDisks -VMName 'v-2012R2-VBR1' RELATED LINKS https://superwidgets.wordpress.com/category/powershell/