PowerShell script to merge VHD files

param( 
[string]$mergePath = $(throw "You must provide the full path for the merging VHD"),
[string]$parentPath = $(throw "You must provide the full path of the parent VHD")
)
$ImageMgtService = get-wmiobject -class "Msvm_ImageManagementService" -namespace "root\virtualization"
$result = $ImageMgtService.MergeVirtualHardDisk($mergePath,$parentPath)
if($result.ReturnValue -eq 4096)
{
$task = [wmi]$result.Job 
while($task.jobstate -lt 7){$task.get()} 
return $task.ErrorCode
}
return $result.ReturnValue

Leave a Reply

Your email address will not be published. Required fields are marked *