In this article I will explain how you can easily identify and disconnect connected CD drives from VM’s on VMware vSphere using a simple PowerCLI command.
Connected CD drives can cause issues when you for example want to remediate your VMware vSphere cluster using the Update Manager.

The operation is not allowed in current state
The operation is not allowed in current state

Find and disconnect all CD drives from VM’s

The first step is to connect to the vCenter server, using the Connect-VIServer command,

The second line of code will identify which VM’s have a mounted CD drive.
All VM’s with a mounted CD drive have a value in the IsoPath:

Get-VM | Where-Object {$_.PowerState –eq “PoweredOn”} | Get-CDDrive | FT Parent, IsoPath

all-vms-with-connected-cd-drive

The third line of code will select all VM’s and change the state of the media to No Media.

Get-VM | Where-Object {$_.PowerState –eq “PoweredOn”} | Get-CDDrive | Set-CDDrive -NoMedia -Confirm:$False

Now, run the first command again.
After running the command, you will see that the ISOPath for all VM’s is empty now.

IsoPath is empty!
IsoPath is empty!

Good luck!

Other PowerCLI related blogs can be found here

Loading

By Marc Roeleveld

VCDX-DCV #299 | Cloud Architect | Owner at Roeleveld Cloud Services

One thought on “PowerCLI – Identify and disconnect all CD drives from VMs”
  1. Hi,

    I’m trying to list VMs that have the CD/DVD drive set to “Datastore ISO File”, but only those who doesn’t have the ISO set as “Connected”

    This lists the VMs with the CD/DVD drive set to “Datastore ISO File”:
    Get-VM | Get-CDDrive | Where {$_.ISOPath -ne $null} | Select Parent, ConnectionState | FT -AutoSize

    But this lists all VMs with the CD Drive set to “Datastore ISO File”, even if it’s Connected or NotConnected,
    I only want the script to list those VMs that has the CD Drive set to “Datastore ISO File” AND are NotConnected. Please advise.

Leave a Reply

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