≡ Menu

Find drive letter of CD Drive using Powershell

Do you ever wanted to know if a remote computer is having CD drive attached to it? or drive letter of CD drive on remote computer? I got similar requirement today and came with below method after some research.

There is a WMI class named Win32_CDROMDrive in Windows which stores the details of CD ROM drive connected in a computer. This WMI class can give you variety of information about the connected CD Drive like status, Drive Letter, manufacturer, etc. In this post I will show you how to query drive letter and manufacturer details of remote computers.

Code:

function Get-CDROMDetails {                        
[cmdletbinding()]                        
param(                        
    [parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]                        
    [string[]]$ComputerName = $env:COMPUTERNAME                        
)                        
            
begin {}                        
process {                        
    foreach($Computer in $COmputerName) {                        
    $object = New-Object –TypeName PSObject –Prop(@{                        
                'ComputerName'=$Computer.ToUpper();                        
                'CDROMDrive'= $null;                        
                'Manufacturer'=$null                        
               })                        
    if(!(Test-Connection -ComputerName $Computer -Count 1 -ErrorAction 0)) {                        
        Write-Verbose "$Computer is OFFLINE"                        
    }                        
    try {                        
        $cd = Get-WMIObject -Class Win32_CDROMDrive -ComputerName $Computer -ErrorAction Stop                        
    } catch {                        
        Write-Verbose "Failed to Query WMI Class"                        
        Continue;                        
    }                        
            
    $Object.CDROMDrive = $cd.Drive                        
    $Object.Manufacturer = $cd.caption                        
    $Object                           
            
    }                        
}                        
            
end {}               
}

Usage and Output:

To get CDROM details of remote computers, try the below command.

PS:\>Get-CDROMDetails -ComputerName TIBPC1, TIBDC1

Hope this helps…

{ 1 comment… add one }

Leave a Comment