Sometimes we may need to update our ISO file in our ESXi datastore. Using this script, we can add the newly uploaded ISO file to all our running VMs without having to shut them down.
Log in to ESXi through Putty. Get the location of your Datastore folder and replace it below.
I have a folder with all my ISO files. Copy the following code, paste it into your favorite text editor, and change the Database name.
An easy way to find out the datastore numbers' names cd /vmfs/volumes/
Copy
Search Site
Search Google
then ls
Copy
Search Site
Search Google
This will show you all the folders. Find your Datastore that holds your ISO files. cd MyDrive-213
Copy
Search Site
Search Google
This will display your numbered name. Select your numbered name. And paste it in place of the PlaceHolder below.
#!/bin/sh# Change this to your actual datastore path="/vmfs/volumes/PlaceHolder/ISO/2026ToolsComplete.iso"=$(vim-cmd vmsvc/getallvms | awk '{print $1}' | grep-E '^[0-9]+')
for VM ID in; do # Get the key for the first CD-ROM drive (usually 3000 series)=$(vim-cmd vmsvc/device.getdevices | grep-B 1 "VirtualCdrom" | grep"key =" | head-n 1 | awk '{print $3}' | sed 's/,//')
if [ -n"$CD KEY" ]; thenecho"Updating VM $VM ID to use $NEW ISO PATH" # Step 1: Update the backing file path # Note: Direct CLI path updates can be complex; PowerCLI is preferred for this step. # This command connects the existing drive:vim-cmd vmsvc/device.connection 1
fi
done