VMware Cloud Community
chrischrischris
Enthusiast
Enthusiast
Jump to solution

How to remove the CDROM from a snapshot?

Hi everyone,

How to remove the CDROM from a snapshot?

I'm trying to move VMs off of datastores by putting the datastores into maintenance mode.

Some VMs will not migrate off because the VM has a snapshot with a mounted CDROM.

The error is:

Remove-CDDrive : 12/11/18 4:04:12 PMRemove-CDDrive      The CDDrive 'CD/DVD drive 1' is not attached to a VM. The requested operation is only supported for devices attached to VM.

At line:15 char:16

+     $r2a = Remove-CDDrive -CD $r2 -Confirm:$false
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo      : InvalidArgument: (CD/DVD drive 1:CDDriveImpl) [Remove-CDDrive], VimException

+ FullyQualifiedErrorId : Client20_VirtualDeviceServiceImpl_TryValidateDeviceOwnerIsVm_IsDatastore,VMware.VimAutomation.ViCore.Cmdlets.Commands.RemoveCDDrive

Below is my code.  It successfully removes CDROMs from VMs but fails to remove the CDROM from a snapshot.  Any assistance would be appreciated.

# list / remove mounted CDROMs including on snapshots --assumes one snapshot

$vms | % {

   $r1 = get-vm $_.Name | Get-CDDrive

   $r2 = get-vm $_.Name | Get-Snapshot | Get-CDDrive

   if (($r1.IsoPath) -or ($r2.IsoPath)) {write-host $_.Name -ForegroundColor green}

   if ($r1.IsoPath) {

   write-host (" Main has CD mounted: {0}" -f $r1.IsoPath)

   write-host (" Removing CD")

   $r1a = $r1 | Remove-CDDrive -Confirm:$false

  }

   if ($r2.IsoPath) {

   write-host (" Snapshot has CD mounted: {0}" -f $r2.IsoPath)

   write-host (" Parent VM: {0}" -f $r2.Parent)

   write-host (" Removing CD")

   $r2a = Remove-CDDrive -CD $r2 -Confirm:$false

  }

}

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You can do something like this

Get-VM | Get-CDDrive | where{$_.IsoPath} | Set-CDDrive -NoMedia -Confirm:$false


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

View solution in original post

0 Kudos
4 Replies
chrischrischris
Enthusiast
Enthusiast
Jump to solution

Drat.

I get this error on trying to remove CDROM from some but not all of the VMs:

Remove-CDDrive : 12/11/18 4:09:47 PMRemove-CDDrive      The VM must be in the following state: PoweredOff.

At line:9 char:22

+     $r1a = $r1 | Remove-CDDrive -Confirm:$false
+                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo      : InvalidOperation: (PoweredOn:PowerState) [Remove-CDDrive], ViError

+ FullyQualifiedErrorId : Common_SharedParameterHelper_VerifyVmIsInState_VmNotInState,VMware.VimAutomation.ViCore.Cmdlets.Commands.RemoveCDDrive

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You are trying to remove the CDROM drive itself, which is not possible while a VM is powered on.

In fact, you normally don't need to remove the CDROM drive itself, you only need to unmount the ISO file that was mounted on that CDROM drive.

What did you have mounted on the CDROM drive?
And if it was an ISO file, was it perhaps located on the datastore you are trying to place in maintenance?

And no, you can't afaik, remove a CDROM drive, or a mounted ISO, from a snapshot, without reverting to that snapshot.

Best solution is to remove all snapshots.
And since a snapshot is not a backup, that shouldn't be an issue :smileygrin:


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

0 Kudos
chrischrischris
Enthusiast
Enthusiast
Jump to solution

Hi Luc,

Thanks!  You're right, each problem-VM has an ISO mounted in its CD-ROM and so the VM is not migrating properly.

How do I force a VM to eject a mounted CDROM ISO?

Thanks!

-Chris

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can do something like this

Get-VM | Get-CDDrive | where{$_.IsoPath} | Set-CDDrive -NoMedia -Confirm:$false


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

0 Kudos