Power CLI – Find CD-ROM with ISO attached

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

Image-0001

Prompt will ask for confirmation, lets give it “A” Yes to All
Image-0002

If you check your vSphere Client, Under recent tasks you can see the VMs being reconfigured.
Image-0004

Now lets check the CD-ROM using our 1st liner.
Image-0005
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.
Image-0006

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s