Eject a CD/DVD Drive with Powershell

Here's a quick Powershell script to eject all CD/DVD drives on a computer.  This uses the WMPlayer COM object.

 

$wm = New-Object -ComObject "WMPlayer.ocx"

$drives = $wm.cdromCollection

for($i = 0; $i -lt $drives.Count; $i++)

{

    $drives.Item($i).Eject()

}

 

Feedback is always welcome.  Enjoy!

Your rating: None Average: 2.3 (26 votes)