Home > PowerCLI, Powershell > Tracking down those connected CD-ROMS with PowerCLI

Tracking down those connected CD-ROMS with PowerCLI

August 13th, 2010

Here are some handy script lines for working out what CDs you have connected which can cause Vmotion to fail.
You don’t always want to disconnect all CDs. If you have .ISOs on shared storage Vmotion will be fine as long as the hosts can both see the .ISO files.

Get the names of VMs with connected CD drives:

get-vm | where { $_ | get-cddrive | where { $_.ConnectionState.Connected -eq "true" } } | select Name

Get the names of VMs with connected .ISOs

get-vm | where { $_ | get-cddrive | where { $_.ConnectionState.Connected -eq "true" -and $_.ISOPath -like "*.ISO*"} } | select Name, @{Name=".ISO Path";Expression={(Get-CDDrive $_).isopath }}

Disconnect all VMs where the CD Drive is connected and it is not an .ISO

$VMs = Get-VM
$CDConnected = Get-CDDrive $VMs | where { ($_.ConnectionState.Connected -eq "true") -and ($_.ISOPath -notlike "*.ISO*")}
If ($CDConnected -ne $null) {Set-CDDrive -connected 0 -StartConnected 0 $CDConnected -Confirm:$false }

or another slightly quicker and dirtier way thanks to commenter José de Alonso

Get-VM | Get-CDDrive | Where {$_.ISOPath -ne $null} | Set-CDDrive -NoMedia -Confirm:$false


Categories: PowerCLI, Powershell Tags: , ,
  1. Andy
    October 23rd, 2015 at 15:02 | #1

    Julian, I am surprised no one else has commented on this great bit of PowerCLI. I have 1800 VMs and we had an NFS share that we put ISO files on go bad. It hung ESXi hosts and caused VMs to become unmanageable until the ESXi hosts services were restarted. Pain in the butt finding all the connected shares. This was a great help.

    Have a great day an keep slapping out that nice PowerCLI magic.

  2. Anthony Julian
    December 10th, 2015 at 21:43 | #2

    Thanks Julian!!

  3. Clau
    February 12th, 2016 at 11:19 | #3

    Very usseful script. thank you

  4. July 5th, 2016 at 14:26 | #4

    thank you very much!

  5. Mister Iks
    June 29th, 2017 at 13:02 | #5


  6. Kav
    August 20th, 2017 at 10:33 | #6

    Dude! This script is so usefull. Just what I needed.

  7. José de Alonso
    December 19th, 2017 at 14:29 | #7


    Here is other PowerCLI onliner to disconnect all mounted VM ISOs:

    Get-VM | Get-CDDrive | Where {$_.ISOPath -ne $null} | Set-CDDrive -NoMedia -Confirm:$false

    Extracted from:


  1. No trackbacks yet.
Comments are closed.