Monday, 4 January 2016

Find .ISOs Attached To VMs

To get a list of all .ISOs attached to the CD drive of VMs, run the script below. This will give you the server name that the ISO is connected to, as well as the path to that ISO.

I used this when trying to delete old ISO images from a datastore. The file would not delete as it was still attached to a VM.


Get-VM | where { $_ | Get-CDDrive | where { $_.ConnectionState.Connected -eq "true" -and $_.ISOPath -like "*.ISO*"} } | select Name, @{Name=".ISO Path";Expression={(Get-CDDrive $_).isopath }}