ESXi: Removing an ISO from all running VMs is easy with this Shell script.
I use PuTTY« to connect to all my ESXi hosts. It makes light of heavy work.
View your ESXi VM, and see where the ISO file is located.
In my case, it shows this: [[Dell-213] ISO/2026ToolsComplete.iso]
In this code, change the [ISO PATH] to your path.
Navigate to your Datastore Folder.
Copy and paste the following code.
[ESXi - Remove ISO from CD/DVD Rom from running VMs]
CFFCS | CarrzSynEdit: | CMD (Windows Command Prompt) | L (Linux)
# Define the exact ISO path as shown in your CD/DVD settings
="[Dell-213] ISO/2026ToolsComplete.iso"

# Loop through all VM IDs
for vmid in $(vim-cmd vmsvc/getallvms | awk '{print $1}' | grep -v Vmid); do
    # Check if this VM has the specific ISO mounted
    # We look for the backing filename in the device list
    =$(vim-cmd vmsvc/device.getdevices  | grep -i "$ISO PATH")

    if [ ! -z "$has iso" ]; then
        # Get the key (ID) for the CD/DVD drive holding this ISO
        =$(vim-cmd vmsvc/device.getdevices  | grep -i "$ISO PATH" -B 15 | grep "key =" | tail -n 1 | awk '{print $3}' | sed 's/,//')
        
        if [ ! -z "$devKey" ]; then
            echo "Releasing $ISO PATH from VMID $vmid (Device Key: $devKey)..."
            # Disconnect the device (effectively unmounting the ISO)
            vim-cmd vmsvc/device.connection   0 0 0
        fi
    fi
done

Other Articles Related to this Entry.ESXi add ISO to CD/DVD Rom for all running VMs«