Option Explicit Dim arrCDR( ), arrHDC( ), arrHDD( ), arrHost( ) Dim blnAlignOutput, blnDebug Dim i, intDescLen, intSizeLen, intValidArgs, j, lngSize Dim colItems, objItem, objWMIService Dim strComputer, strInterface, strMsg, strSize blnAlignOutput = True blnDebug = False strComputer = "." intValidArgs = 0 ' Parse command line With WScript.Arguments If .Count > 3 Then Syntax If .Unnamed.Count > 1 Then Syntax If .Unnamed.Count = 1 Then If strComputer <> "." Then Syntax Else strComputer = .Unnamed(0) intValidArgs = intValidArgs + 1 End If End If If .Named.Exists( "HELP" ) Then Syntax If .Named.Exists( "?" ) Then Syntax If .Named.Exists( "D" ) Then blnDebug = True intValidArgs = intValidArgs + 1 End If If .Named.Exists( "R" ) Then If strComputer <> "." Then Syntax Else strComputer = .Named.Item( "R" ) intValidArgs = intValidArgs + 1 End If End If If .Named.Exists( "T" ) Then blnAlignOutput = False intValidArgs = intValidArgs + 1 End If ' Check if more arguments were passed than the ones we recognized If intValidArgs <> .Count Then WScript.Echo vbCrLf & "ERROR: Invalid command line argument(s)" Syntax End If End With If Trim( strComputer ) = "" Then WScript.Echo vbCrLf & "ERROR: Specify a computer name when using the /R switch" Syntax End If On Error Resume Next Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" ) If Err Then WScript.Echo vbCrLf & "ERROR: " & Err.Description Syntax End If On Error Goto 0 ' Query HDD properties and save results in HDD array Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_DiskDrive" ) ReDim arrHDD( 3, colItems.Count - 1 ) For Each objItem in colItems With objItem lngSize = 0 strSize = "0 " If Not IsNull( objItem.Size ) Then lngSize = CInt( .Size / 1073741824 ) ' divide by 1 GB If lngSize > 0 Then strSize = CStr( lngSize ) & " GB" Else lngSize = CInt( .Size / 1048576 ) ' divide by 1 MB strSize = CStr( lngSize ) & " MB" End If End If If IsNull( .InterFaceType ) Or .InterfaceType = "" Then If Left( .PnpDeviceID, 3 ) = "USB" Then strInterface = "USB" Else strInterface = "-" End If Else strInterface = .InterfaceType End If arrHDD( 0, .Index ) = .Caption arrHDD( 1, .Index ) = .PnpDeviceID arrHDD( 2, .Index ) = strSize arrHDD( 3, .Index ) = strInterface End With Next ' Query CDR properties and save results in CDR array Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_CDROMDrive" ) ReDim arrCDR( 3, colItems.Count - 1 ) i = 0 For Each objItem in colItems With objItem If Left( .PnpDeviceID, 3 ) = "USB" Then strInterface = "USB" Else strInterface = "-" End If arrCDR( 0, i ) = .Caption arrCDR( 1, i ) = .PnpDeviceID arrCDR( 2, i ) = .Drive arrCDR( 3, i ) = strInterface End With i = i + 1 Next ' Query harddisk and USB controller properties and save results in HDC array Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_IDEController" ) ReDim arrHDC( 2, colItems.Count - 1 ) i = 0 For Each objItem in colItems With objItem arrHDC( 0, i ) = UCase( .Caption & " (" & .Description & ")" ) arrHDC( 1, i ) = .PNPDeviceID ' This is one of two "weakest links" in this script: differentiating between IDE (PATA) and SATA ' depends on the words SATA or S-ATA or Serial ATA in the harddisk controller's description field If InStr( arrHDC( 0, i ), "SATA" ) Then arrHDC( 2, i ) = "SATA" ElseIf InStr( arrHDC( 0, i ), "S-ATA" ) Then arrHDC( 2, i ) = "SATA" ElseIf InStr( arrHDC( 0, i ), "SERIAL ATA" ) Then arrHDC( 2, i ) = "SATA" Else arrHDC( 2, i ) = "IDE" End If End With i = i + 1 Next Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_SCSIController" ) ReDim Preserve arrHDC( 2, UBound( arrHDC, 2 ) + colItems.Count ) For Each objItem in colItems With objItem arrHDC( 0, i ) = UCase( .Caption & " (" & .Description & ")" ) arrHDC( 1, i ) = .PNPDeviceID arrHDC( 2, i ) = "SCSI" End With i = i + 1 Next Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_USBController" ) ReDim Preserve arrHDC( 2, UBound( arrHDC, 2 ) + colItems.Count ) For Each objItem in colItems With objItem arrHDC( 0, i ) = UCase( .Caption & " (" & .Description & ")" ) arrHDC( 1, i ) = .PNPDeviceID ' This is the second "weakest links" in this script: differentiating between "classic" USB and USB 3.0 depends on the words ' "USB 3" in the harddisk controller's description field, or its PnP Device ID starting with "NUSB3" (NEC/Renesas only) If InStr( arrHDC( 0, i ), "USB 3" ) Then arrHDC( 2, i ) = "USB3" ElseIf Left( arrHDC( 0, i ), 5 ) = "NUSB3" Then arrHDC( 1, i ) = "USB3" Else arrHDC( 2, i ) = "USB" End If End With i = i + 1 Next ' Query hosted drives and save results in Host array Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_IDEControllerDevice" ) ReDim arrHost( 2, colItems.Count - 1 ) i = 0 For Each objItem in colItems With objItem arrHost( 0, i ) = Replace( .Antecedent, "\\", "\", 3 ) arrHost( 1, i ) = Replace( .Dependent, "\\", "\", 3 ) End With i = i + 1 Next Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_SCSIControllerDevice" ) ReDim Preserve arrHost( 2, UBound( arrHost, 2 ) + colItems.Count ) For Each objItem in colItems With objItem arrHost( 0, i ) = Replace( .Antecedent, "\\", "\", 3 ) arrHost( 1, i ) = Replace( .Dependent, "\\", "\", 3 ) End With i = i + 1 Next Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_USBControllerDevice" ) ReDim Preserve arrHost( 2, UBound( arrHost, 2 ) + colItems.Count ) For Each objItem in colItems With objItem arrHost( 0, i ) = Replace( .Antecedent, "\\", "\", 3 ) arrHost( 1, i ) = Replace( .Dependent, "\\", "\", 3 ) End With i = i + 1 Next ' Check interface per hosted disk For i = 0 To UBound( arrHost, 2 ) For j = 0 To UBound( arrHDC, 2 ) If InStr( arrHost( 0, i ), arrHDC( 1, j ) ) Then arrHost( 2, i ) = arrHDC( 2, j ) End If Next Next ' Match hosted disks array with HDD array For i = 0 To UBound( arrHDD, 2 ) For j = 0 To UBound( arrHost, 2 ) If InStr( arrHost( 1, j ), arrHDD( 1, i ) ) Then arrHDD( 3, i ) = arrHost( 2, j ) End If Next Next For i = 0 To UBound( arrCDR, 2 ) For j = 0 To UBound( arrHost, 2 ) If InStr( arrHost( 1, j ), arrCDR( 1, i ) ) Then arrCDR( 3, i ) = arrHost( 2, j ) End If Next Next ' Display intermediate data If blnDebug Then For i = 0 To UBound( arrHDD, 2 ) WScript.Echo """HDD" & i & """,""" & arrHDD( 0, i ) & """,""" & arrHDD( 1, i ) & """,""" & arrHDD( 2, i ) & """,""" & arrHDD( 3, i ) & """" Next WScript.Echo For i = 0 To UBound( arrCDR, 2 ) WScript.Echo """CDROM" & i & """,""" & arrCDR( 0, i ) & """,""" & arrCDR( 1, i ) & """,""" & arrCDR( 2, i ) & """,""" & arrCDR( 3, i ) & """" Next WScript.Echo For i = 0 To UBound( arrHDC, 2 ) WScript.Echo """HDC" & i & """,""" & arrHDC( 0, i ) & """,""" & arrHDC( 1, i ) & """,""" & arrHDC( 2, i ) & """" Next WScript.Echo For i = 0 To UBound( arrHost, 2 ) WScript.Echo """Host" & i & """,""" & arrHost( 0, i ) & """,""" & arrHost( 1, i ) & """,""" & arrHost( 2, i ) & """" Next WScript.Echo End If ' Display results intDescLen = 0 intSizeLen = 0 For i = 0 To UBound( arrHDD, 2 ) If Len( arrHDD( 0, i ) ) > intDescLen Then intDescLen = Len( arrHDD( 0, i ) ) End If If Len( arrHDD( 2, i ) ) > intSizeLen Then intSizeLen = Len( arrHDD( 2, i ) ) End If Next For i = 0 To UBound( arrCDR, 2 ) If Len( arrCDR( 0, i ) ) > intDescLen Then intDescLen = Len( arrCDR( 0, i ) ) End If Next For i = 0 To UBound( arrHDD, 2 ) If blnAlignOutput Then WScript.Echo "HDD" & i & vbTab & Left( arrHDD( 0, i ) & Space( intDescLen ), intDescLen ) & vbTab & arrHDD( 3, i ) & vbTab & Right( Space( intSizeLen ) & arrHDD( 2, i ), intSizeLen ) Else WScript.Echo "HDD" & i & vbTab & arrHDD( 0, i ) & vbTab & arrHDD( 3, i ) & vbTab & arrHDD( 2, i ) End If Next For i = 0 To UBound( arrCDR, 2 ) If blnAlignOutput Then WScript.Echo "CDROM" & i & vbTab & Left( arrCDR( 0, i ) & Space( intDescLen ), intDescLen ) & vbTab & arrCDR( 3, i ) & vbTab & Right( Space( intSizeLen + 3 ) & arrCDR( 2, i ), intSizeLen ) Else WScript.Echo "CDROM" & i & vbTab & arrCDR( 0, i ) & vbTab & arrCDR( 3, i ) & vbTab & arrCDR( 2, i ) End If Next Set objItem = Nothing Set colItems = Nothing Set objWMIService = Nothing Sub Syntax strMsg = vbCrLf _ & "DiskTypes.vbs, Version 1.00 BETA" _ & vbCrLf _ & "List disk drives and their interface type (IDE/SATA/SCSI/USB/USB3) and capacity" _ & vbCrLf & vbCrLf _ & "Usage: DISKTYPES.VBS [ /R:computer ] [ /T ] [ /D ]" _ & vbCrLf & vbCrLf _ & "Where: /R:computer query remote computer" _ & vbCrLf _ & " /T generate tab delimited output" _ & vbCrLf _ & " /D show intermediate results (for debugging)" _ & vbCrLf & vbCrLf _ & "Notes: Differentiation between IDE and SATA depends on the words ""SATA"" or" _ & vbCrLf _ & " ""S-ATA"" or ""Serial ATA"" in the harddisk controller's description field;" _ & vbCrLf _ & " this is far from fool-proof, but so far the least unreliable method" _ & vbCrLf _ & " available for scripting." _ & vbCrLf _ & " Likewise, detection of USB 3.0 depends on the words ""USB 3"" in the USB" _ & vbCrLf _ & " controller's descrition, or ""NUSB3"" in its PnP Device ID; the latter is" _ & vbCrLf _ & " true only for NEC/Renesas controllers." _ & vbCrLf _ & " ""SCSI"" signifies either true SCSI or RAID enabled IDE/SATA controllers." _ & vbCrLf _ & " ""USB3"" signifies the USB port; the device may still be USB 2.0 or 1.1." _ & vbCrLf & vbCrLf _ & "Written by Rob van der Woude" _ & vbCrLf _ & "http://www.robvanderwoude.com" WScript.Echo strMsg WScript.Quit 1 End Sub