I'm trying to create a list of VMs whish a specific ISO attached. However when I run the following, it does not tell me the name of the VM. I need the VM name to verify with the VM owner that I can remove the ISO as they may using the ISO.
PS C:\Program Files (x86)\VMware\Infrastructure\VIToolkitForWindows> $vms | get-cddrive | where {$_.ISOPath -like "*2.0.8.iso*"}
Here is a snippet of the results:
IsoPath : [TestSAN-DC1-Vol1] ISOs/SMG_WinPE20_x86_v2.0.8.iso HostDevice : RemoteDevice : ConnectionState : VMware.VimAutomation.Client20.ConnectInfoImpl Id : VirtualMachine-vm-1148/3000 Name : CD/DVD Drive 1
Message was edited by: halr9000: used code and noformat tags to pretty it up
I'd try something like this:
foreach ($vm in $vms) {
if ( $vm | get-cddrive | where {$_.ISOPath -like "*2.0.8.iso*"} ) {
Write-Output $vm
}
}
[PowerShell MVP|https://mvp.support.microsoft.com/profile=5547F213-A069-45F8-B5D1-17E5BD3F362F], VI Toolkit forum moderator
Author of the upcoming book: Managing VMware Infrastructure with PowerShell
Co-Host, PowerScripting Podcast (http://powerscripting.net)
This might work:
Get-VM | Where-Object { $Null -ne ($_ | Get-CDdrive | Where-Object { $_.ISOPath -like "*2.0.8.iso*"})}
Oops: Just saw Hal's. It looks like it will work too.
