Freigeben über


How can I get a my servers Network Adapter(s) driver filename and version info using Powershell?

 

I’d like to be able to pull the same info I can see in Driver File Details from Powershell.

I’ve seen some ways people have been pulling this info from Win32_PNPSignedDriver  

Get-WMIObject Win32_PnPSignedDriver |where {$_.Devicename -like "*82567LM-3 Gigabit Network Connection*"}

 __GENUS : 2__CLASS : Win32_PnPSignedDriver__SUPERCLASS : CIM_Service__DYNASTY : CIM_ManagedSystemElement__RELPATH :__PROPERTY_COUNT : 28__DERIVATION : {CIM_Service, CIM_LogicalElement, CIM_ManagedSystemElement}__SERVER : BEN-SRV__NAMESPACE : root\cimv2__PATH :Caption :ClassGuid : {4d36e972-e325-11ce-bfc1-08002be10318}CompatID : PCI\VEN_8086&DEV_10DE&REV_02CreationClassName :Description : Intel(R) 82567LM-3 Gigabit Network ConnectionDeviceClass : NETDeviceID : PCI\VEN_8086&DEV_10DE&SUBSYS_02761028&REV_02\3&172E68DD&0&C8DeviceName : Intel(R) 82567LM-3 Gigabit Network ConnectionDevLoader :DriverDate : 20081021000000.******+***DriverName :DriverProviderName : MicrosoftDriverVersion : 10.5.1.0FriendlyName :HardWareID : PCI\VEN_8086&DEV_10DE&SUBSYS_02761028&REV_02InfName : net1kx64.infInstallDate :IsSigned : TrueLocation : PCI bus 0, device 25, function 0Manufacturer : IntelName :PDO : \Device\NTPNP_PCI0005Signer : Microsoft WindowsStarted :StartMode :Status :SystemCreationClassName :SystemName :

This doesn’t give me any of the file info and I need to know what NICs I’m searching for before I run the command so I can apply a filter. In a lot of environments you may not know all the types of NICs installed or you may want all the network adapters on the system.

I can use WMI_NetworkAdapter to pull the network adapters but it doesn’t give me the file info either.

Get-WMIObject Win32_NetworkAdapter

ServiceName : e1kexpressMACAddress : <Withheld>AdapterType : Ethernet 802.3DeviceID : 7Name : Intel(R) 82567LM-3 Gigabit Network ConnectionNetworkAddresses :Speed :

I can use Win32_SystemDriver to get the file path and name but again I would need to know beforehand information about the effectively apply a filter. If I can’t find a useful filter I’m left with a lot of information to sort through.

$SystemDrivers = gwmi -computer $Server Win32_SystemDriver

foreach ($SystemDriver in $SystemDrivers){

   "Display Name : $($SystemDriver.DisplayName)" "Name : $($SystemDriver.Name)" "Path : $($SystemDriver.PathName)" ""}

Display Name : Intel(R) PRO/1000 PCI Express Network Connection Driver KName : e1kexpressPath : C:\Windows\system32\DRIVERS\e1k60x64.sys

What I need to do is list the network adapters from WMI_Networkadapter and get the file info from Win32_SystemDriver. It would be way to convenient for me to be able to use a name or display name property but those don’t match so it isn’t an option.

Intel(R) 82567LM-3 Gigabit Network Connection != Intel(R) PRO/1000 PCI Express Network Connection Driver K

The only property that is the same on both WMI classes is the Win32_SystemDriver name and the Win32_NetworkAdapter serviename. This is the same as the service name found in the registry at HKLM\System\CurrentControlSet\Services\<servicename>

Display Name : e1kexpress == ServiceName : e1kexpress

This gives me two options. I can enumerate the networkadapters using WMI_Networkadapter and use the servicename(s) to query the registry or enumerate the networkadapters using WMI_Networkadapter and find the instances where the Win32_SystemDriver name property matches the WMI_Networkadapter servicename

Here is how to do it using both WMI Classes

$Server = $args[0]

if ($Server){

    #Get the network adapters $NetworkAdapters = gwmi -computer $Server win32_networkadapter $arrBinary = @() #Go through each adapter and pull the SystemDriver Info foreach ($Adapter in $NetworkAdapters) { $Drivers = gwmi -computer $Server Win32_SystemDriver #look at each driver foreach ($Driver in $Drivers) { #If the Win32_SystemDriver name matches the Win32_NetworkAdapter serviename we have a match if ($Driver.name -eq $Adapter.servicename) { $Binary = New-Object System.Object $Trim = $Driver.PathName.Replace("C:\","c$\") $Trim2 = $Trim.Replace("\??\","") $FileVers = [System.Diagnostics.FileVersionInfo]::GetVersionInfo("\\" + $Server + "\" + $Trim2) $Binary | add-Member -MemberType NoteProperty -Name Adapter -Value $Adapter.Name $Binary | add-Member -MemberType NoteProperty -Name Path -Value $Driver.pathname $Binary | add-Member -MemberType NoteProperty -Name FileVer -Value $FileVers.fileversion $arrBinary += $Binary }

        } } $arrBinary}

Here is a faster way

$Server = $args[0]

if ($Server){

    #Get the network adapters $NetworkAdapters = gwmi -computer $Server win32_networkadapter $arrBinary = @() #Go through each adapter and pull the SystemDriver Info foreach ($Adapter in $NetworkAdapters) { $Binary = New-Object System.Object $Reg = Get-ItemProperty -path "HKLM:\System\CurrentControlSet\Services\$($Adapter.servicename)"

        $FileVers = [System.Diagnostics.FileVersionInfo]::GetVersionInfo("\\" + $Server + "\c$\Windows\" + $($Reg.ImagePath)) $Binary | add-Member -MemberType NoteProperty -Name Adapter -Value $Adapter.Name $Binary | add-Member -MemberType NoteProperty -Name Path -Value $FileVers.FileName $Binary | add-Member -MemberType NoteProperty -Name FileVer -Value $FileVers.fileversion $arrBinary += $Binary } $arrBinary}

Comments

  • Anonymous
    January 01, 2003
    The comment has been removed
  • Anonymous
    October 11, 2010
    And if the device name is unknown? For example, you should collect such data from local network?