Powershell to query all DiskControllers and its associated diskdrives


  • We have a requirement to get diskcontrollers(SCSI or IDE or other) and its associated diskdrives using WMI and Powershell. Have seen the documentation of WIN32_SCSIController ,Win32_IDEController and WIN32_DiskDrive. Can somebody advise how to connect/relate the information between controller class and driveinfo class using powershell.

    thanks in advance


    Thursday, March 01, 2012 3:33 PM

All replies

  • Have you work with ASSOCIATORS OF before?  If not, this is a good high level overview:

    Page 21, in particular, begins the conceptual discussion.

    Thursday, March 01, 2012 3:44 PM
  • Here  is the example of WIN32_DiskDrive class. For other just replace class name

    $Drives = Get-WmiObject -Class WIN32_DiskDrive -ComputerName $server
    Foreach($Drive in $Drives)

    Hope this helps...!!!

    Thanks & Regards
    Bhavik Solanki

    Please click “Mark as Answer” if this post answers your question and click "Vote as Helpful if this Post helps you.

    Thursday, March 01, 2012 4:42 PM
  • Hi,

    Based on my research, Win32_DiskDrive class has a property named InterfaceType :

    Data type: string
    Access type: Read-only

    Interface type of physical disk drive.

    The values are:






    For more information, please refer to the below link:

    Win32_DiskDrive class


    Hope this helps.

    Best Regards,

    Yan Li

    Yan Li

    TechNet Community Support

    Friday, March 02, 2012 6:27 AM
  • Yes . I can see the InterfaceType as SCSI.

    The issue is I have mulitple SCSI controllers in the host. Want to query all the disk drives associated with each controller. Which property in Win32_DiskDrive can be used to identify the corresponding SCSI controllers



    Friday, March 02, 2012 8:25 AM
  • Hi,

    Please try below code: returns information about all the SCSI controllers found on a computer:

    On Error Resume Next
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_SCSIController")
    For Each objItem in colItems
        Wscript.Echo "Availability: " & objItem.Availability
        Wscript.Echo "Configuration Manager Error Code: " & _
        Wscript.Echo "Configuration Manager User Configuration: " & _
        Wscript.Echo "Device ID: " & objItem.DeviceID
        Wscript.Echo "Driver Name: " & objItem.DriverName
        Wscript.Echo "Name: " & objItem.Name
        Wscript.Echo "PNP Device ID: " & objItem.PNPDeviceID
        Wscript.Echo "Protocol Supported: " & objItem.ProtocolSupported
        Wscript.Echo "Status Information: " & objItem.StatusInfo

    Best Regards,

    Yan Li

    Yan Li

    TechNet Community Support

    Monday, March 05, 2012 5:19 AM
  • How can i do the association between Win32_SCSIController and Win32_DiskDrive


    Tuesday, March 06, 2012 3:44 AM
  • try this
    $disks = gwmi win32_diskdrive
    foreach($disk in $disks)
    didn’t test it, but shy of using WMI Associator queries you can use the

    Justin Rich
    PowerShell V3 Guide (Technet)
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Tuesday, March 06, 2012 1:25 PM
  • Tried the above code and evaluated the properties of Win32_scsicontroller .All the properties are returning empty

    Can you please help


    Tuesday, March 06, 2012 2:59 PM
  • yeah im not sure how the getrelated works, but it will probably only go so
    many hops, so to speak...
    you'll have to walk your way through it I think...
    also you might even need to look at the vendors namespace to make the
    connection because of things like MPIO.. a disk isnt directly mapped to a
    controller port...

    Justin Rich
    PowerShell V3 Guide (Technet)
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Tuesday, March 06, 2012 3:10 PM
  • Hello,

    Although this has been posted almost 2 years ago, since I too had this similar/associated problem and I could not find any answers, I just wanted to mention my solution (for me, I am looking specific to SCSI Controller, but you can probably substitute other controller such as CIM_Controller and CIM_ControlledBy respectively I'm sure):

    1. Query for Win32_SCSIController and record its "__RELPATH"
    2. Query for Win32_SCSIControllerDevice and locate its "__RELPATH", in it you should find a DeviceID and Entity.PNPDeviceID.
    3. Match the DeviceID from step 2 and if it can find a match, then the SCSIController has a device attached to it (else the controller is there but no device/media connected/mounted)
    4. Query for Win32_DiskDrive (for me, I am using WHERE clause of "WHERE InterfaceType='SCSI'" to narrow my search) and match the "PNPDeviceID" with the Entity.PNPDeviceID found in step #2

    All in all, the binding missing-link is to associate/map the Win32_SCSIController and Win32_DiskDrive via data found in Win32_SCSIControllerDevice.

    Monday, July 28, 2014 10:55 PM
  • Sorry for the necrothreading,  but this page is the first result on google, and I was trying to find if someone found a better way then I.

    Anyway,  that's how I got it using powershell and wmi ASSOCIATOR statement. This goes from Controller to logical Disk. This code will might not work if you have mutliple disk / paritions / logcial disk.  You'd need some loops to handle all possibilities.

    #Get the Controller
    $eStataController=gwmi -query 'SELECT * FROM Win32_scsiController WHERE Name="Silicon Image SiI 3132 SATALink Controller"'
    #Get the PnpEntity linked for this controller.  It will get itself,  so I only keep the ones that the service is disk.  I get 2 disk heres.
    $disk=(gwmi -query ('ASSOCIATORS OF {' + $eStataController.path + '} WHERE ResultClass=Win32_PnPEntity' ))| Where {$_.Service -eq "disk"}
    #Find the Disk Drive Linked to the first disk received.  (Loops could be used to managed multiple disk. 
    $diskDrive=(gwmi -query ('ASSOCIATORS OF {' + $disk[0].path + '} WHERE ResultClass=Win32_DiskDrive'))
    #Find the Partition Linked to the disk. Could be more than one.  Loops should be used.
    $partition=gwmi -query ('ASSOCIATORS OF {' + $DiskDrive.path + '} WHERE ResultClass=Win32_DiskPartition')
    #Find the Logical Disk Linked to the partition. Could be more than one.  Loops should be used.
    $logicalDisk=gwmi -query ('ASSOCIATORS OF {' + $partition.path + '} WHERE ResultClass=Win32_LogicalDisk')

    Friday, April 29, 2016 2:43 PM