I needed to eject a
optical disc
drive tray from a
command-line
interface (CLI) on a system running Microsoft Windows 11 so that
I could insert a DVD in the drive. That can be done using the
Powershell
command powershell (New-Object -ComObject
WMPlayer.OCX.7).cdromCollection.item(0).Eject(), which will
eject the tray of the first optical drive found by Windows Media Player's
COM object.
PS C:\> powershell (New-Object -ComObject WMPlayer.OCX.7).cdromCollection.item(0).Eject() Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows PS C:\>
