[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

Leave a Reply

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

Back to Blog