Search code examples
powershellwmihardwarewmi-query

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.


Solution

  • 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.