Techibee.com

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

Exit mobile version