Option Explicit Dim arrCDR( ), arrHDC( ), arrHDD( ), arrHost( ) Dim blnAlignOutput, blnDebug Dim i, intCDR, intDescLen, intHDC, intHDD, intHost, intSizeLen, j, lngSize Dim colItems, objItem, objWMIService Dim strComputer, strInterface, strMsg blnAlignOutput = True blnDebug = False strComputer = "." ' 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) End If End If If .Named.Exists( "HELP" ) Then Syntax If .Named.Exists( "?" ) Then Syntax If .Named.Exists( "D" ) Then blnDebug = True End If If .Named.Exists( "R" ) Then If strComputer <> "." Then Syntax Else strComputer = .Named.Item( "R" ) End If End If If .Named.Exists( "T" ) Then blnAlignOutput = False 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 ' Count number of harddisks Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_DiskDrive", , 48 ) intHDD = -1 For Each objItem in colItems intHDD = intHDD + 1 Next ' Adjust size of HDD array ReDim arrHDD( intHDD, 3 ) ' Query HDD properties and save results in HDD array Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_DiskDrive", , 48 ) For Each objItem in colItems With objItem If IsNull( objItem.Size ) Then lngSize = 0 Else lngSize = CInt( .Size / 1073741824 ) End If If Left( .PnpDeviceID, 3 ) = "USB" Then strInterface = "USB" Else strInterface = "-" End If arrHDD( .Index, 0 ) = .Caption arrHDD( .Index, 1 ) = .PnpDeviceID arrHDD( .Index, 2 ) = lngSize arrHDD( .Index, 3 ) = strInterface End With Next ' Count number of CDROM drives Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_CDROMDrive", , 48 ) intCDR = -1 For Each objItem in colItems intCDR = intCDR + 1 Next ' Adjust size of CDR array ReDim arrCDR( intCDR, 3 ) ' Query CDR properties and save results in CDR array Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_CDROMDrive", , 48 ) i = 0 For Each objItem in colItems With objItem If Left( .PnpDeviceID, 3 ) = "USB" Then strInterface = "USB" Else strInterface = "-" End If arrCDR( i, 0 ) = .Caption arrCDR( i, 1 ) = .PnpDeviceID arrCDR( i, 2 ) = .Drive arrCDR( i, 3 ) = strInterface End With i = i + 1 Next ' Count number of harddisk controllers Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_IDEController", , 48 ) intHDC = -1 For Each objItem in colItems intHDC = intHDC + 1 Next Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_SCSIController", , 48 ) For Each objItem in colItems intHDC = intHDC + 1 Next ' Adjust size of IDE array ReDim arrHDC( intHDC, 2 ) ' Query harddisk controller properties and save results in HDC array Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_IDEController", , 48 ) i = 0 For Each objItem in colItems With objItem arrHDC( i, 0 ) = UCase( .Caption & " (" & .Description & ")" ) arrHDC( i, 1 ) = .PNPDeviceID ' This is the "weakest link" in this script: differentiating between IDE and SATA depends ' on the words SATA or S-ATA or Serial ATA in the harddisk controller's description field If InStr( arrHDC( i, 0 ), "SATA" ) Then arrHDC( i, 2 ) = "SATA" ElseIf InStr( arrHDC( i, 0 ), "S-ATA" ) Then arrHDC( i, 2 ) = "SATA" ElseIf InStr( arrHDC( i, 0 ), "SERIAL ATA" ) Then arrHDC( i, 2 ) = "SATA" Else arrHDC( i, 2 ) = "IDE" End If End With i = i + 1 Next Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_SCSIController", , 48 ) For Each objItem in colItems With objItem arrHDC( i, 0 ) = UCase( .Caption & " (" & .Description & ")" ) arrHDC( i, 1 ) = .PNPDeviceID arrHDC( i, 2 ) = "SCSI" End With i = i + 1 Next ' Count number of hosted drives Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_IDEControllerDevice", , 48 ) intHost = -1 For Each objItem in colItems intHost = intHost + 1 Next Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_SCSIControllerDevice", , 48 ) For Each objItem in colItems intHost = intHost + 1 Next ' Adjust size of Host array ReDim arrHost( intHost, 2 ) ' Query hosted drives and save results in Host array Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_IDEControllerDevice", , 48 ) i = 0 For Each objItem in colItems With objItem arrHost( i, 0 ) = Replace( .Antecedent, "\\", "\", 3 ) arrHost( i, 1 ) = Replace( .Dependent, "\\", "\", 3 ) End With i = i + 1 Next Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_SCSIControllerDevice", , 48 ) For Each objItem in colItems With objItem arrHost( i, 0 ) = Replace( .Antecedent, "\\", "\", 3 ) arrHost( i, 1 ) = Replace( .Dependent, "\\", "\", 3 ) End With i = i + 1 Next ' Check interface per hosted disk For i = 0 To intHost For j = 0 To intHDC If InStr( arrHost( i, 0 ), arrHDC( j, 1 ) ) Then arrHost( i, 2 ) = arrHDC( j, 2 ) End If Next Next ' Match hosted disks array with HDD array For i = 0 To intHDD For j = 0 To intHost If InStr( arrHost( j, 1 ), arrHDD( i, 1 ) ) Then arrHDD( i, 3 ) = arrHost( j, 2 ) End If Next Next For i = 0 To intCDR For j = 0 To intHost If InStr( arrHost( j, 1 ), arrCDR( i, 1 ) ) Then arrCDR( i, 3 ) = arrHost( j, 2 ) End If Next Next ' Display intermediate data If blnDebug Then For i = 0 To intHDD WScript.Echo """HDD" & i & """,""" & arrHDD( i, 0 ) & """,""" & arrHDD( i, 1 ) & """,""" & arrHDD( i, 2 ) & """,""" & arrHDD( i, 3 ) & """" Next WScript.Echo For i = 0 To intCDR WScript.Echo """CDROM" & i & """,""" & arrCDR( i, 0 ) & """,""" & arrCDR( i, 1 ) & """,""" & arrCDR( i, 2 ) & """,""" & arrCDR( i, 3 ) & """" Next WScript.Echo For i = 0 To intHDC WScript.Echo """HDC" & i & """,""" & arrHDC( i, 0 ) & """,""" & arrHDC( i, 1 ) & """,""" & arrHDC( i, 2 ) & """" Next WScript.Echo For i = 0 To intHost WScript.Echo """Host" & i & """,""" & arrHost( i, 0 ) & """,""" & arrHost( i, 1 ) & """,""" & arrHost( i, 2 ) & """" Next WScript.Echo End If ' Display results intDescLen = 0 intSizeLen = 0 For i = 0 To intHDD If Len( arrHDD( i, 0 ) ) > intDescLen Then intDescLen = Len( arrHDD( i, 0 ) ) End If If Len( arrHDD( i, 2 ) ) > intSizeLen Then intSizeLen = Len( arrHDD( i, 2 ) ) End If Next For i = 0 To intCDR If Len( arrCDR( i, 0 ) ) > intDescLen Then intDescLen = Len( arrCDR( i, 0 ) ) End If Next For i = 0 To intHDD If blnAlignOutput Then WScript.Echo "HDD" & i & vbTab & Left( arrHDD( i, 0 ) & Space( intDescLen ), intDescLen ) & vbTab & arrHDD( i, 3 ) & vbTab & Right( Space( intSizeLen ) & arrHDD( i, 2 ), intSizeLen ) & " GB" Else WScript.Echo "HDD" & i & vbTab & arrHDD( i, 0 ) & vbTab & arrHDD( i, 3 ) & vbTab & arrHDD( i, 2 ) & " GB" End If Next For i = 0 To intCDR If blnAlignOutput Then WScript.Echo "CDROM" & i & vbTab & Left( arrCDR( i, 0 ) & Space( intDescLen ), intDescLen ) & vbTab & arrCDR( i, 3 ) & vbTab & Right( Space( intSizeLen + 3 ) & arrCDR( i, 2 ), intSizeLen + 3 ) Else WScript.Echo "CDROM" & i & vbTab & arrCDR( i, 0 ) & vbTab & arrCDR( i, 3 ) & vbTab & arrCDR( i, 2 ) End If Next Set objItem = Nothing Set colItems = Nothing Set objWMIService = Nothing Sub Syntax strMsg = vbCrLf _ & "DiskTypes.vbs, Version 0.20 beta" _ & vbCrLf _ & "List harddisk and CDROM drives, and their interface type (IDE/SATA/SCSI)" _ & 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 _ & "Note: Differentiation between IDE and SATA depends on the words ""SATA""" _ & vbCrLf _ & " or ""S-ATA"" or ""Serial ATA"" in the harddisk controller's" _ & vbCrLf _ & " description field; this is far from fool-proof, but so far the" _ & vbCrLf _ & " least unreliable method available for scripting." _ & vbCrLf & vbCrLf _ & "Written by Rob van der Woude" _ & vbCrLf _ & "http://www.robvanderwoude.com" WScript.Echo strMsg WScript.Quit 1 End Sub