Can't dismount a VHD

Mar 27, 2011 at 9:30 PM

Using PsHyperV R2 SP1 on WS2008 R2. VHD is mounted as SCSI.

Trying to create a command to remove all drives from all VMs on a host that contain "backup" in the VHD filename. This is the command I'm using:

get-VMdisk | where {$_.diskpath -match "backup"} | foreach {remove-VMDrive -diskonly -VM $_.VMelementName -controllerId $_.controllerId -L $_.driveLun}

There is no error posted, and get-VMdisk no longer lists the disk. But the disk is still present in the VM, and visible in the Hyper-V Console.

I've also tried the same thing with this command:

dismount-vhd "F:\GuestBackups\01infr001Cbackup2.vhd"

After confirming that I want to dismount it, I get this error:

Test-WMIResult : The Dismount operation for F:\GuestBackups\01infr001Cbackup2.vhd returned a fa
ilure response of: InvalidParameter
At C:\Program Files\modules\hyperV\Disk.ps1:431 char:35
+                     Test-wmiResult <<<<  -result ($ImageManagementService.Unmount($VHDPath))
-wait -JobWaitText ($lStr_DiskDismounting + $vhdPath) `
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Test-WMIResult