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

Tracking down those connected CD-ROMS with PowerCLI

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 }
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!

  1. No trackbacks yet.
 

Time limit is exhausted. Please reload the CAPTCHA.