none
WMI script to get active network adapter and driver information

    Question

  • Trying to figure out how to get my WMI script to give me only the active Network card's driver date and version. I have 2 parts to the script and I need to tell the second part to only display from the results from the first part. The first part discovers the connected network card's name. The second part displays all drivers under the "net" device class. I want to only echo the connected driver (which the first part does just fine) and then ONLY the driver name, date, and version for that adapter, and if there are more than one connected adapters (like on a server), display the 4 items for the other adapter after the first one.

    On Error Resume Next
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter Where NetConnectionStatus = 2")
    For Each objItem in colItems
        Wscript.Echo "Network Card" & "," & objItem.Name
    next
    Set colItems = objWMIService.ExecQuery("Select * from Win32_PnPSignedDriver where deviceclass = 'net'")
    For Each objItem in colItems
        Wscript.Echo "DeviceName: " & objItem.DeviceName 
        Wscript.Echo "DriverDate: " & objItem.DriverDate
        Wscript.Echo "DriverVersion: " & objItem.DriverVersion
    Next

    Friday, November 09, 2012 4:53 PM

Answers

  • Try adding an AND clause to your query string ...

     "Select * from Win32_PnPSignedDriver where deviceclass = 'net' and Devicename = '" & sActiveName & "'"

    And save the device name from the first query into the sActiveName variable.  For example, ...

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter Where NetConnectionStatus = 2")
    For Each objItem in colItems
        sActiveName = objItem.Name
        Wscript.Echo "Network Card" & "," & sActiveName
    next
    Set colItems = objWMIService.ExecQuery( _
      "Select * from Win32_PnPSignedDriver where deviceclass = 'net' and Devicename = '" & sActiveName & "'")
    For Each objItem in colItems
        Wscript.Echo "DeviceName: " & objItem.DeviceName 
        Wscript.Echo "DriverDate: " & objItem.DriverDate
        Wscript.Echo "DriverVersion: " & objItem.DriverVersion
    Next


    Tom Lavedas

    Friday, November 09, 2012 5:31 PM
    Moderator

All replies

  • Try adding an AND clause to your query string ...

     "Select * from Win32_PnPSignedDriver where deviceclass = 'net' and Devicename = '" & sActiveName & "'"

    And save the device name from the first query into the sActiveName variable.  For example, ...

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter Where NetConnectionStatus = 2")
    For Each objItem in colItems
        sActiveName = objItem.Name
        Wscript.Echo "Network Card" & "," & sActiveName
    next
    Set colItems = objWMIService.ExecQuery( _
      "Select * from Win32_PnPSignedDriver where deviceclass = 'net' and Devicename = '" & sActiveName & "'")
    For Each objItem in colItems
        Wscript.Echo "DeviceName: " & objItem.DeviceName 
        Wscript.Echo "DriverDate: " & objItem.DriverDate
        Wscript.Echo "DriverVersion: " & objItem.DriverVersion
    Next


    Tom Lavedas

    Friday, November 09, 2012 5:31 PM
    Moderator
  • Thanks Tom. I forgot I could do that... long day...

    Anyway, I cleaned it up a bit too. I'm piping the output into a csv, so I inserted a comma in my wscript.echo commands.

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter Where NetConnectionStatus = 2")
    For Each objItem in colItems
        sActiveName = objItem.description
    next
    Set colItems = objWMIService.ExecQuery( _
      "Select * from Win32_PnPSignedDriver where deviceclass = 'net' and Devicename = '" & sActiveName & "'")
    For Each objItem in colItems
        Wscript.Echo "Network Card" & "," & objItem.DeviceName 
        Wscript.Echo "Network Card Driver Date" & "," & left(objItem.DriverDate, 8)
        Wscript.Echo "Network Card Driver Version: " & objItem.DriverVersion
    Next

    Friday, November 09, 2012 5:51 PM
  • How do I run this against multiple wsn or servers. I would like to be able to drop a list of wsn names in a text file and run this script against them. I am still learning VBS and I don't understand how to do this.
    Tuesday, March 25, 2014 12:04 AM
  • Also output to a CSV or txt file. Thank you
    Tuesday, March 25, 2014 12:05 AM