VMware Cloud Community
emcclure
Enthusiast
Enthusiast

Question about Set-CDDrive -NoMedia

So I recently started a new job and was working on a task to decommission a vCenter and its VM's.  Some of them had isos mounted, so we had to go one-by-one figuring out which had what mounted.  I thought it'd be great to have a script that could do this for me.  I did some googling and found some solutions that tell me how to find which VM's have an iso mounted.  I also found scripts that mention how to unmount the iso.

However when I run my script and "unmount" the iso and run it again, it acts as if the iso is still mounted.  For the unmount portion of the code I use this:

Get-VM | Get-CDDrive | Where {$_.IsoPath -ne $null} | Set-CDDrive -NoMedia -Confirm:$False

From what I'm seeing in vCenter after this, when I look at the VM's that this was run on, I still see the drive listed, it shows datastore iso still, but is completely greyed out and the Connected check box is unchecked.  So if I wanted to change it to Client Device or Host Device I couldn't do so without removing the drive completely from the VM and re-adding it back.  Is that to be expected with the -NoMedia part?  If so is there a way to just unmount the iso and change it to either the Host or Client device?  I just don't want to cause a problem where someone else goes into the VM's and sees that the drive isn't really there and be confused, especially if the script is run on multiple machines.

I hope I explained this well, please let me know if anything else is needed.

Thank you in advance.

0 Kudos
6 Replies
LucD
Leadership
Leadership

Some Guest OS keep a lock on the CDdrive and don't take action on the NoMedia implicit unmount.
Hence the greyed out situation, because for vSphere the unmount was initiated.

In that case your only solution, as you already noticed, is to remove/add the CDdrive I'm afraid.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
emcclure
Enthusiast
Enthusiast

Thanks @LucD for the response.  I was afraid that was the case.  These have mainly been Windows OSes.  It looks like to remove/add a drive to a VM, the VM has to be powered off, which doesn't do me a lot of good if a machine is running and still needs to be running.  Is there a way around that at all with PowerCLI or is that just wishful thinking?

0 Kudos
LucD
Leadership
Leadership

Afaik, you can't safely do that, besides the NOMedia option you tried.
It is after all pulling a device away, with which the Guest OS has to deal.



Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
emcclure
Enthusiast
Enthusiast

Thanks for the info @LucD .  So the machines I tested this on weren't powered on, so would there still be a lock?  It's been a little while for me working with VMware products, but I don't recall having that issue when a VM was powered off and I did things the old manual way.

0 Kudos
LucD
Leadership
Leadership

When the VM is powered off, the NoMedia should work.
Perhaps the Where-clause is not letting the CDDrive through.
Try without, only for the problematic VM of course.

Get-VM -Name <problematic-VM> | Get-CDDrive | Set-CDDrive -NoMedia -Confirm:$False


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
emcclure
Enthusiast
Enthusiast

Thanks @LucD , I'll give it a shot once my permissions get fixed as it doesn't seem to want me to run this on one of the VM's as it tells me Permissions to perform this operation was denied. 

0 Kudos