none
Powershell to query all DiskControllers and its associated diskdrives

    Question

  • 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


    c

    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:

    http://www.ravichaganti.com/blog/?p=1979

    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)
    {
    	$Drive
    }

    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 :

    InterfaceType
    Data type: string
    Access type: Read-only

    Interface type of physical disk drive.

    The values are:

    SCSI

    HDC

    IDE

    USB

    1394

    For more information, please refer to the below link:

    Win32_DiskDrive class

    http://msdn.microsoft.com/en-us/library/windows/desktop/aa394132(v=vs.85).aspx#properties

    Get-WmiObject

    http://technet.microsoft.com/en-us/library/dd315295.aspx

    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

    thanks


    c

    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: " & _
            objItem.ConfigManagerErrorCode
        Wscript.Echo "Configuration Manager User Configuration: " & _
            objItem.ConfigManagerUserConfig
        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
        Wscript.Echo
    Next

    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

    c

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

    Justin Rich
    http://jrich523.wordpress.com
    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


    c

    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
    http://jrich523.wordpress.com
    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