build 980262fe | content blog-content@c8490fa · 338 posts | profiles 20 · corpus 208 | 0 skipped |
Scripting · 2017-07-31

Find and disconnect CD Drives on your VMs

One of the things that regularly pops up in our health checks in VMware environments are connected CD Drives that prevent DRS from functioning properly or prevents a host from entering maintenance

2017-07-31Date
Dario DörflingerAuthor
1Min read
153words
Topics capabilities · idf weight Automation automation 1.80
Vendors vendors · idf weight VMware vmware 0.91

This post is from 2017. It stays online because people still look for it, but it describes the products as they were then.

One of the things that regularly pops up in our health checks in VMware environments are connected CD Drives that prevent DRS from functioning properly or prevents a host from entering maintenance mode when doing thing like patching.

In large environments it can get very tedious to disconnect all those drives manually. With PowerCLI it is just one line.

If you want to free up a host for maintenance mode you can do it with two lines:

Get-VMHost <your host> |Get-VM | Where-Object {$_.PowerState -eq "PoweredOn"} | Get-CDDrive | Set-CDDrive -NoMedia -Confirm:$False
Get-VMHost <your host>| Set-VMHost -VMHost Host -State "Maintenance"

If you want to disconnect all of your CD-ROMs:

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

If you just want to list all the VMs that have connected CD Drives:

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

Comments

2 comments from the previous blog. We no longer take new ones here.

Stefan Wehrle 2026-08-04

Hi Dario Das funktioniert so lange gut wie die cd unlocked ist. Wenn die Frage beantwortet werden muß wirds leider bunt. Hast du da einen guten Tip zu? Alles was ich bisher dazu fand hab ich bisher nicht zum Laufen bekommen. Liebe Grüße, Stefan

Dario Dörflinger 2026-08-05

Hallo Stefan Danke fürs Nachfragen. Dieser Blogpost ist mittlerweile neun Jahre alt, aber schön dass er noch gelesen wird. Du hast recht, sobald die VM das Laufwerk gesperrt hat, wirft ESXi die VM Question msg.cdromdisconnect.locked und Set-CDDrive bleibt einfach stehen, bis jemand antwortet. In den meisten Fällen ist ein gemountetes VMware Tools ISO schuld. Das bekommst du ganz ohne Rückfrage weg: Get-VM | Where-Object { $_.ExtensionData.Runtime.ToolsInstallerMounted } | Dismount-Tools Wenn wirklich das Guest-OS sperrt, startest du den Reconfigure asynchron und beantwortest die Frage separat: $task = Get-VM MyVM | Get-CDDrive | Set-CDDrive -NoMedia -Confirm:$false -RunAsync Start-Sleep 3 Get-VMQuestion -VM MyVM | Set-VMQuestion -Option "Yes" -Confirm:$false Wait-Task $task Das -RunAsync ist der Teil, an dem es sonst scheitert. Gruss Dario

You might also like