[PowerCLI] Find and disconnect CD Drives on your VMs

Back to Blog

[PowerCLI] 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 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

Share this post

Comments (2)

  • Stefan Wehrle Reply

    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

    04.08.2026 at 17:48
    • Dario Dörflinger Reply

      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

      05.08.2026 at 07:35

Leave a Reply

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

Back to Blog