I was recently looking at retrieving a number of VMs where the CD Drive was connected to a Datastore ISO file. This is possible be using the Get-CDDrive cmdlet to retrieve the device type information. To retreive information for a single VM we can use the following:
Get-VM VM1 | Get-CDDrive
The below information will be retrieved, where the IsoPath value is the Datastore ISO filename and Parent is the name of the VM.
IsoPath : [********] SW_DVD9_SQL_Svr_Enterprise_Edtn_2008_R2_English_MLF_X16-29540.ISO HostDevice : RemoteDevice : ParentId : VirtualMachine-vm-15465 Parent : vm1 Uid : /VIServer=domain\user1@server1:443/VirtualMachine=VirtualMachine-vm-15465/CDDrive=3002/ ConnectionState : Connected, GuestControl, StartConnected ExtensionData : VMware.Vim.VirtualCdrom Id : VirtualMachine-vm-15465/3002 Name : CD/DVD drive 1 Client : VMware.VimAutomation.ViCore.Impl.V1.VimClient
For a number of VMs, we can retrieve theses as a collection and pass these to the Get-CDDrive cmdlet. In this instance I wanted to return all VMs where the CD Drive was connected to the Datastore ISO file ‘SW_DVD9_SQL_Svr_Enterprise_Edtn_2008_R2_English_MLF_X16-29540.ISO’.
The Datastore ISO file value can be retrieved from the IsoPath property, in the below example we will filter the retrieved information to return only the above file and include only the name of the VM and the IsoPath in the output.
Get-VM | Get-CDDrive | Select Parent, IsoPath | Where-Object {$_.IsoPath -like "*SW_DVD9_SQL_Svr_Enterprise_Edtn_2008_R2_English_MLF_X16-29540.ISO"}
We may also choose to remove the connected Datastore ISO file by using the output from the above and passing to the Set-CDDrive cmdlet to remove the media.
Get-VM | Get-CDDrive | Where-Object {$_.IsoPath -like "*SW_DVD9_SQL_Svr_Enterprise_Edtn_2008_R2_English_MLF_X16-29540.ISO"} | Set-CDDrive -NoMedia -Confirm:$False