PowerCLI – Find ISO attached to Virtual Machines

4
I was recently talking one of the customers where the Virtual Machine was showing up on one of the wrong Storage clusters.
On further investigation, I found that this was happening due to the fact that the ISO mounted on the Virtual Machine was coming from one of the datastores that were part of another datastore cluster.
I am not sure how did they manage to do that as those LUNs were not presented to the host on which the Virtual Machine was running. My guess is that someone must have manually inserted the path to the ISO image.
Anyhow, by removing the path, we were able to resolve the issue and the Virtual Machine was no more showing up on the datastore cluster.
Now the customer had multiple such VMs and was looking for an easy way to figure out the ISO image attached to all the VMs in his environment.
Imagine doing this on each and every VM in the environment from the vSphere Client and noting it down. I am still dreading just the thought of it.
And here comes PowerCLI to the rescue.
Hence, the article is titled PowerCLI - Find ISO attached to Virtual Machines.
I knew that there was a command that would fetch the details related to the CD Drive attached to the VM, which is Get-CDDrive.
Now I had to mix it up with the Get-VM command and fetch the results which would show me the Virtual Machine name and the attached ISO on the Virtual Machine.
To find the properties of the Get-CDDrive, I piped it to Get-Member and found that the Parent property lists the Virtual Machine name.

Get-CDDrive VMName | Get-Member

PowerCLI - Find ISO attached to Virtual Machines
So below is the script that will fetch all the VMs in the environment and the ISOs attached to them.

Connect-VIServer vCenterServerName -User username -Password password
$VMs = Get-VM
$Output = foreach ($VM in $VMs){
Get-CDDrive $VM | select Parent, IsoPath
}
$Output | Export-Csv C:\Results.csv -NoTypeInformation

The output of the csv file will look something like below.

PowerCLI - Find ISO attached to Virtual Machines

Well, that's all I have for today, I hope this has been informative and thank you for reading!

Share.

About Author

I am Adil Arif, working as a Senior Technical Support Engineer at Rubrik as well as an independent blogger and founder of Enterprise Daddy. In my current role, I am supporting infrastructure related to Windows and VMware datacenters.

4 Comments

Leave A Reply