VMware script remove CD media

Often I forget to go back and unmount ISO files in VMware. This isn't normally a problem unless you want to do something like delete a storage target, but it is a pain to try and location which VM has the ISO mounted by hand in the vSphere client. This script will remove the ISO media from all VMs. You will need the VMware Power CLI installed to use this script.

Code:

$server = "server IP"
$user = "domain\user"
$pwd = "user's password"
 
Connect-VIServer $server -User $user -Password $pwd
 
$vms = Get-VM
write "`nVM's with CD-ROM device type set to 'Datastore ISO file' :"
foreach ($vm in $vms | where { $_ | Get-CDDrive | where { $_.ISOPath -like "*.ISO*"} | Set-CDDrive -Nomedia -confirm:$false })  {
                write $vm.name
              
}
No feedback yet