PowerCLI: List all vm's with ISO mounted and dismount them

PowerCLI: List all vm's with ISO mounted and dismount them

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

6 comments

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}}
}
}
}

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.

Leave a Reply

Your email address will not be published. Required fields are marked *