≡ Menu

Eject CD drive in windows using powershell

I have seen some page hits to my blog where people are searching for “power shell code for ejecting CD drive” and landing at my post which describes the procedure using VBscript. So, posting the powershell equivalent code here for such peoples reference.

$items = (New-Object -com "WMPlayer.OCX.7").cdromcollection.item(0)            
$items.eject()            

The above code ejects a CD drive. If you have want to close the CD drive repeat the second statement again. If you have multiple CD drives, you need to play with array object in second line to eject/close a specific CD drive.

Happy Learning..,
Sitaram Pamarthi

Comments on this entry are closed.

  • zimonic December 8, 2012, 1:00 pm

    Hi, thanks for this post! However, this does not work on my Windows 7 laptop with Windows Media Player uninstalled from Control Panel. So how to do both eject and close without the OCX?