Cannot mount VHD as it conflicts with other disks

Sometimes you can run into problems mounting VHD's.  I see it when people start testing/developing scripts.  The most common error is :

Error (13226)
Virtual hard disk <path to VHD> cannot be mounted on host myhost.mydomain.local because it conflicts with other disks.

All this means is that anothe process as already mounted your VHD.  To unmount, all you have to do is run a simple script.

 #Specify the VHD that is mounted

$VHDName = "<full path to file>" 



#Get the MSVM_ImageManagementService

$VHDService = get-wmiobject -class "Msvm_ImageManagementService" -namespace "root\virtualization" -computername "." 



 #UnMount the VHD

$Result = $VHDService.UnMount($VHDName)