VMware PowerCLI

The Best User Interface for your VMware Datacenter!

Set-CDDrive -Force switch

When trying to dismount a CD ISO mounted in an OS, it's very common that the OS has some hold on that ISO that will cause attempts to disconnect the CDDrive to create a VM Question asking for confirmation to force the dismount. One can attempt complicated methods to answer the question, but I think it would make more sense (and more efficient) if we can effectively bypass such questions (or auto-answer them) with use of a -Force switch.

So if I call:

    $vmObj | Get-CDDrive | Set-CDDrive -NoMedia -Confirm:$false

it will attempt to gracefully eject the CDDrive and if the OS has a lock on it, will spawn the VM question as now.

However, if I call:

    $vmObj | Get-CDDrive | Set-CDDrive -NoMedia -Confirm:$false -Force

It will bypass the question (or auto-answer it) and dismount the ISO even if the OS has a lock on it.

  • RYAN ROLAND
  • Feb 25 2019
  • Looking for Feedback
  • Attach files
  • Guest commented
    August 16, 2020 15:30

    Force option doesn't seem to exist..

    Set-CDDrive : A parameter cannot be found that matches parameter name 'Force'.

    At line:1 char:58

    + $vm | Get-CDDrive | Set-CDDrive -NoMedia -Confirm:$false -Force

    + ~~~~~~

    + CategoryInfo : InvalidArgument: (:) [Set-CDDrive], ParameterBindingException

    + FullyQualifiedErrorId : NamedParameterNotFound,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.SetCDDrive

  • Travis Brock commented
    June 03, 2020 18:32

    Does anyone have a workaround they can share? Currently without asynchronous or force, the only idea I have is to spin up a second instance just to watch for and answer the question when Set-CDDrive is run.