Reading Time: 2 minutes

Hi everyone! Just dropping by to share with all of you a couple of one-liners that will definitely save you some time. There are times in which during casual VM operations such as booting a VM or even maintenance in VMM library, a VM may fail to start. Most of the times is because an Image file that was previously mounted on this particular VM, has been moved, corrupted or even deleted from its original location.

Error of missing Image File.

There are also times in which users or Hyper-V Operators, have mounted Image files on a VM and forgot to dismount it after finishing up. For all these reasons, please feel free to use the following One-Liners in order to track down VMs that have mounted Images whether they are running on a standalone Hyper-V host or within a Failover Cluster.

For VMs that are running on a standalone host (Windows Server, Windows Desktop).

Get-VMDvdDrive -VMName * | Where-Object {$_.DvdMediaType -eq 'ISO'}

For VMs that are running within a Failover Cluster.

Get-ClusterGroup | ? {$_.GroupType -eq 'VirtualMachine' } | Get-VM | Get-VMDvdDrive | Where-Object {$_.DvdMediaType -eq 'ISO'}

Now the juicy part, you managed to track down all these mounted Images (existing or non existing). What will you do? Obviously you need to dismount them from the VMs. In order to accomplish that, you need to add this tiny bit of PowerShell code below followed by a pipeline.

| Remove-VMDvdDrive -Path $null

Thanks for reading my blog!

Feel free to drop your comment or question below.