I wanted to find out which of my VMs in VMWare is having ISO attached to its CD-Rom. Its quite annoying to go to each VM property and check for CD-Rom.
This Power CLI liner will help us a lot.
Get-VM | Where-Object {$_.PowerState –eq “PoweredOn”} | Get-CDDrive | FT Parent, IsoPath
Get-VM – as it says, gives you all the VMs in your virtual infrastructure.
Where-Object{$_.PowerState – eq “PoweredOn”} – this will find only those VMs which are online
Get-CDDrive – All the VMs that we collected using Get-VM and Where-Object will be passed on to Get-CDDrive as value for parameter “–VM” and Next we will search the results that we got in Get-CDDrive by specifying the Objects that we need like “Parent” which is the name of VM and IsoPath which is the path of ISO file that is attached to CD-ROM.
Removing / Dismounting ISO from CD-ROM.
Now are we have list of VMs which has ISO attached to CD- ROM, lets remove them just by a one-liner.
Get-VM | Where-Object {$_.PowerState –eq “PoweredOn”} | Get-CDDrive | Set-CDDrive –NoMedia
Prompt will ask for confirmation, lets give it “A” Yes to All
If you check your vSphere Client, Under recent tasks you can see the VMs being reconfigured.
Now lets check the CD-ROM using our 1st liner.
There is no value displayed under IsoPath, as the ISO has been detached from CD-ROM.
Lets also check the properties of any one VM from GUI.