Easy-peasy and a pretty short post…
To get all vm’s with iso mounted:
Get-VM | Get-CDDrive | select @{N="VM";E="Parent"},IsoPath | where {$_.IsoPath -ne $null}
Then, to dismount those:
Get-VM | Get-CDDrive | where {$_.IsoPath -ne $null} | Set-CDDrive -NoMedia -Confirm:$False
Thanks a lot. Works like a charm!
Here is another option to list all VM’s with a mounted ISO…
Get-View -ViewType VirtualMachine | %{
$name = $_.name
$_.Config.Hardware.Device | where {$_ -is [vmware.vim.virtualcdrom]} | %{
if($_.Connectable.Connected -eq $true){
Write-Progress -Activity “Collecting VMs” -CurrentOperation $name
$_ | Select-Object @{e={$Name};n=’ComputerName’},@{n=’Label’;e={$_.DeviceInfo.Label}},@{n=’Summary’;e={$_.DeviceInfo.Summary}}
}
}
}
I would recommend to add additional “-Connected $Falase” in Set-CDDrive
Used this in a script I wrote that powered off and exports VMs to the desktop. Needed this snippet to remove all ISO prior to export.
Worked great. Thank you.