Finding CD-ROM Drives

by May 7, 2009

You can find out whether a system has CD-Drives by using a little function that returns all drive letters from all CD Drives in your system:

function Get-CDDrives {
@(Get-WmiObject win32_logicaldisk filter 'DriveType=5' |
ForEach-Object { $_.DeviceID })

To get the list of CD Drives, simply call the function:


To find out how many CD drives are available, you should use the Count property:


To find out whether there are CD-ROM drives at all, use check for Count greater than 0:

(Get-CDDrives).Count -gt 0

If you want to exclude CD-ROM drives with no media inserted, check the Access property. It is 0 for no media, 1 for read access, 2 for write access and 3 for both:

Get-WmiObject win32_logicaldisk filter 'DriveType=5 and Access>0'