Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell - check if a CD is in CD-ROM drive

Is this possible?

My first guess would be something like:

C:> Get-WmiObject Win32_CDROMDrive

But when I tried this, it only tells me Caption, Drive, Manufacturer,VolumeName

No information on whether or not there is a CD in the disc drive.

like image 997
Kellen Stuart Avatar asked Jun 20 '17 17:06

Kellen Stuart


People also ask

How do I detect a CD-ROM?

Microsoft Windows usersOpen System Information. In the System Information window, click the + symbol next to Components. If you see "CD-ROM," click it once to display the CD-ROM in the left window.

How do I list drives in PowerShell?

For a list of the Windows PowerShell drives in your Windows PowerShell session, use the Get-PSDrive cmdlet. Although the drives in the display vary with the drives on your system, the listing will look similar to the output of the Get-PSDrive command shown above.

How do I know if my CD-ROM is working?

In the Run dialog box, type devmgmt. msc then press the Enter key. In the Device Manager window, expand DVD/CD-ROM drives. Verify that the optical drive is listed.

What does the command get-PSDrive do?

The Get-PSDrive cmdlet gets the drives in the current session. You can get a particular drive or all drives in the session. This cmdlet gets the following types of drives: Windows logical drives on the computer, including drives mapped to network shares.


1 Answers

You can get this information by

(Get-WMIObject -Class Win32_CDROMDrive -Property *).MediaLoaded

You can see what properties are available for that WMI class by

Get-WMIObject -Class Win32_CDROMDrive -Property * | Get-Member

and more detailed documentation from

Get-WMIHelp -Class Win32_CDROMDrive

In general, you will find that liberal use of the Get-Help, Get-Member, Get-Command, and Get-WMIHelp cmdlets will provide you with a great deal of information, and possibly eliminate the need to ask questions like this here and wait for an answer that may or may not come.

like image 100
Jeff Zeitlin Avatar answered Oct 31 '22 19:10

Jeff Zeitlin