none
Windows driver version is not the latest returned by WMI

    Question

  • Hi Experts,

    I am writing a script to install and upgrade/downgrade a device driver. I am supposed to verify the driver version after every upgrade/downgrade. I am using the following command to get the driver version,

    $DeviceInfo = Get-WMIObject Win32_PnPSignedDriver | where {$_.Devicename -like $deviceType}

    The problem I face is that after an upgrade/downgrade, the Get-WMIObject command still shows old driver version. When I check the driver version from device manager I can see the new version is reflected there. 

    I suspect that Get-WMIObject is returning stale data. My questions are, 

    1. How do I refresh the WMI object to get latest driver version ?
    2. Is there an alternative way to get driver version ?


    -Pranav

    Wednesday, April 11, 2012 2:21 PM

Answers

All replies

  • if you open a new session and query again does it show the new driver version?

    what about a reboot?

    my guess is that if something doesnt trigger the new version number then the install method you are using is leaving something out.

    also, based on the way you wrote the question, i assume you arent just inspecting the original variable but you are calling GWMI again correct?


    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.

    Wednesday, April 11, 2012 5:05 PM
  • Hi,

    No, I run the Get-WMIObject command again to fetch the driver version after install, so I run Get-WMIObject once before and once after the upgrade/downgrade. The install method I use is a normal msiexec command with the MSI package name. For instance if I have a build 2.1.0.40364, it remains same (2.1.0.40364) after the downgrade too, although device manager shows the downgraded version 2.1.0.39555.

    The query shows correct version after a reboot. I haven't tried running the query in a new PS session.


    -Pranav


    • Edited by pranavkojha Thursday, April 12, 2012 12:15 AM added details
    Thursday, April 12, 2012 12:05 AM
  • Just tried running the command in new PS session, it still shows the stale driver version.

    -Pranav

    Thursday, April 12, 2012 12:26 AM
  • hmm, there is probably a .net class or maybe win32 api you could call, but i fear it would get complex then.

    my guess with the WMI is that the system just doesnt always update it.. maybe its on an interval or upon some sort of request...  it gets the data from CIM_Service, so maybe could dig in to there?

    im not really sure but i guess you'll likely need to look else where for the data


    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.

    Thursday, April 12, 2012 12:43 AM
  • Hi,

    Wonder if I could use C# code to get the same data, not sure it would work, but how can I use the below C# code in powershell ?

    ManagementObjectSearcher searcher =
                        new ManagementObjectSearcher("root\\CIMV2",
                        "SELECT * FROM Win32_PnPSignedDriver");
                        ManagementObjectCollection moc = searcher.Get();
    
                        foreach (var manObj in moc)
                        {
                            Console.WriteLine("Device Name: {0}\r\nDeviceID: {1}\r\nDriverDate: {2}\r\nDriverVersion: {3}\r\n==============================\r\n", manObj["FriendlyName"], manObj["DeviceID"], manObj["DriverDate"], manObj["DriverVersion"]);
                        }
    This code should return the driver details too...


    -Pranav


    • Edited by pranavkojha Thursday, April 12, 2012 1:35 AM edit
    Thursday, April 12, 2012 1:35 AM
  • Microsoft has a tool called "devcon.exe" which is freely available on their website. Just discovered that we can use this tool for getting the latest driver version, 

    PS C:\Users\Administrator> $vfasbus_drivers=devcon drivernodes vfasbus\*
    PS C:\Users\Administrator> $vfasbus_drivers
    VFASBUS\STRM&PCI_VEN_1A78&DEV_00310\5&2245F57&0&00
        Name: Virident FlashMAX card
    Driver node #0:
        Inf file is C:\Windows\INF\oem3.inf
        Inf section is vgcm
        Driver description is Virident FlashMAX card
        Manufacturer name is Virident Systems
        Provider name is Virident Systems
        Driver date is 3/29/2012
        Driver version is 2.1.0.40594
        Driver node rank is 2164195328
        Driver node flags are 00040040
    1 matching device(s) found.
    PS C:\Users\Administrator>


    Likewise, if you need drivers for PCI or SCSI devices, you can use the following commands, 

    PS C:\Users\Administrator> $pci_drivers=devcon drivernodes pci\*
    PS C:\Users\Administrator> $scsi_drivers=devcon drivernodes scsi\*

    To get a list of all devices, just use * as the argument for driver nodes. Putting it here just incase someone finds it useful.


    -Pranav


    • Edited by pranavkojha Thursday, April 12, 2012 4:50 AM edit
    Thursday, April 12, 2012 4:49 AM
  • you'd do a query with get-wmiobject -query "SELECT * FROM
    Win32_PnPSignedDriver" -namespace root\cimv2
     
    as far as that tool, yes that is one way to pull it, just wonder where its
    getting its data from.
     
     

    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.
    Thursday, April 12, 2012 12:22 PM