I have a VMware ESXi 6 host with several guests running on it. There is a datastore with an ISO file that is in use by one or more of these clients. I am accessing the ESXi host through ssh from linux, so PowerCLI is not an option.

Q1: How can I, from the VMware CLI, find out which guests have this ISO file mounted?

Q2: How can I, once I know that, unmount this ISO file from these guests, also from the VMware CLI?

I expect it to be vim-cmd vmsvc subcommands, but I haven't been able to find them.

2 Answers 2


A quick & crude solution on the shell via SSH would be to write a small script that connects several actions:

  1. Get your VM IDs with vim-cmd vmsvc/getallvms|awk '{print $1}'|grep -o -E '[0-9]+' (list all VMs, only show first column with awk, filter out IPs and text and empty lines with grep)
  2. Iterate over the lines (ash does not have arrays like bash) and check for each number/ID if one occurrence of your chosen ISO name is found in the device listing for each VM: vim-cmd vmsvc/device.getdevices yourVmId|grep -o -A 12 -E 'yourImageName.iso' | grep -c 'connected = true' (list all devices, get the area around your ISO file, check if the ISO is currently mounted/active)
  3. Get the device ID of each CD drive (assuming it is only one, change the code for multiple drives on a single machine) with a modified grep from the same initial listing: vim-cmd vmsvc/device.getdevices yourVmId|grep -o -B 4 -E 'yourImageName.iso'|grep -o -E 'key = [0-9]+'|grep -o -E '[0-9]+' (double grep is neccessary because of missing group option -P)
  4. Use vim-cmd vmsvc/device.connection yourVmId yourDeviceId disconnect to disconnect the device. (Edit: It seems that this is not entirely correct, it does something, but not what I would expect. I'll update when I have time to investigate this further)

The only problem I encountered is that the message "CD drive locked by guest" may appear in the VSphere client while doing the last step, but maybe this can be disabled generally.

  • Thanks for this very elaborate answer! The disconnect fails for me as well, but it seems to be the correct way to do it. Sep 6, 2016 at 9:10
  • @rolek Glad I could help, thank you for accepting the answer. The strange thing I noticed is even after successful disconnect and state change in the Vsphere client, the hardware configuration window does not change - ISO is still mounted and in the same state. I did not test if this is only cosmetic, but I suspect there may be another way to remove the discs correctly.
    – user121391
    Sep 6, 2016 at 9:20
  • (you're supposed to use PowerCLI)
    – ewwhite
    Sep 6, 2016 at 9:32
  • 1
    @ewwhite Is PowerCLI available for Linux? Sep 6, 2016 at 9:34

Use PowerCLI...

Or just do it manually for the "several" VMs.
Or avoid the situation in the first place by unmounting after installation.

  • Here is a PowerCLI onliner to disconnect all mounted VM ISOs: Get-VM | Get-CDDrive | Where {$_.ISOPath -ne $null} | Set-CDDrive -NoMedia -Confirm:$false Extracted from: sysadmit.com/2017/12/… Dec 19, 2017 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.