locked
PowerShell To update Drivers of a computer RRS feed

  • Question

  • I am trying to build a powershell script with logic to identify a currently installed driver version.

    if it is the same (as the one i am trying to install or newer) skip the install.

    If it is lower than the version i am trying to install execute a setup.exe with silent argument.

    $NetworkName = Get-WmiObject Win32_PnPSignedDriver| select devicename, driverversion | where {$_.devicename -eq 'Intel(R) Ethernet Connection (7) I219-LM'}

    If ($_.Driverversion -ge '12.17.8.9') { 

    Write-Output "Version is Current"

    return 0

    } Else {

    start-process -filepath "\\servername\share\share\Dell\Drivers\Dell 3630\Network Card\setup.exe" -argumentlist '/s' -Wait -NoNewWindow

    }

    this works and installs the newest driver, but it doesn't skip computers that already have the newest version.

    Any help would be greatly appreciated, i did a lot of googling but since i am still learning, i am pretty sure its just a rookie overlook.

    Wednesday, March 6, 2019 7:02 PM

Answers

  • It works because you ALWAYS install the driver because your if condition will never be true because $_ does not exist. You create a variable $NetworkName but you don't use it.

    Try it htis way:

    $NetworkName = Get-WmiObject Win32_PnPSignedDriver | 
        Where-Object {$_.devicename -eq 'Intel(R) Ethernet Connection (7) I219-LM'}| 
            Select-Object devicename, driverversion
    
    If ([System.Version]$NetworkName.Driverversion -ge [System.Version]'12.17.8.9') { 
        Write-Output "Version is Current"
    } 
    Else {
        Start-Process -filepath "\\servername\share\share\Dell\Drivers\Dell 3630\Network Card\setup.exe" -ArgumentList '/s' -Wait -NoNewWindow
    }
    And the next rime please, format your code as code using the code posting tool provided on the edit ar of the post editor. Thanks.


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''



    • Edited by BOfH-666 Wednesday, March 6, 2019 7:22 PM
    • Marked as answer by tech_1000 Wednesday, March 6, 2019 7:44 PM
    • Unmarked as answer by tech_1000 Thursday, March 7, 2019 6:21 PM
    • Marked as answer by tech_1000 Thursday, March 7, 2019 6:23 PM
    Wednesday, March 6, 2019 7:20 PM

All replies

  • It works because you ALWAYS install the driver because your if condition will never be true because $_ does not exist. You create a variable $NetworkName but you don't use it.

    Try it htis way:

    $NetworkName = Get-WmiObject Win32_PnPSignedDriver | 
        Where-Object {$_.devicename -eq 'Intel(R) Ethernet Connection (7) I219-LM'}| 
            Select-Object devicename, driverversion
    
    If ([System.Version]$NetworkName.Driverversion -ge [System.Version]'12.17.8.9') { 
        Write-Output "Version is Current"
    } 
    Else {
        Start-Process -filepath "\\servername\share\share\Dell\Drivers\Dell 3630\Network Card\setup.exe" -ArgumentList '/s' -Wait -NoNewWindow
    }
    And the next rime please, format your code as code using the code posting tool provided on the edit ar of the post editor. Thanks.


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''



    • Edited by BOfH-666 Wednesday, March 6, 2019 7:22 PM
    • Marked as answer by tech_1000 Wednesday, March 6, 2019 7:44 PM
    • Unmarked as answer by tech_1000 Thursday, March 7, 2019 6:21 PM
    • Marked as answer by tech_1000 Thursday, March 7, 2019 6:23 PM
    Wednesday, March 6, 2019 7:20 PM
  • Notice that he cast the version string to [system.version] as well.  Otherwise unexpected things will happen.

    PS C:\Users\admin> '12.15.22.9' -gt '12.15.22.10'
    True

    PS C:\Users\admin> [version]'12.15.22.9' -gt '12.15.22.10'
    False

    • Edited by JS2010 Wednesday, March 6, 2019 7:47 PM
    Wednesday, March 6, 2019 7:32 PM
  • This worked as expected after your edits, thank you for your assistance, i will make sure to use the edit tool next time.
    Wednesday, March 6, 2019 7:45 PM
  • Understood, thank you for the help!
    Wednesday, March 6, 2019 9:42 PM
  • I wanted to ask for your help one last time, you were really helpful and pointed me in the right direction.

    I am trying to integrate some logic to identify the model of computer and if it does not detect the model or if it detects the model but the driver name doesn't exist abort the whole thing.

    On a a computer that is not the right model and does not have the driver i get the below which is what i want.

    "Driver Doesn't Exist or Model does not match"

    On a the correct model with up to date driver i get both answers back.

    "Version is Current"

    "Driver Doesn't Exist or Model does not match"

    $Model = Get-WmiObject Win32_ComputerSystem | 
        Where-Object {$_.model -eq 'Precision 3630 Tower'}| 
            Select-Object model
    $Driver = Get-WmiObject Win32_PnPSignedDriver | 
        Where-Object {$_.devicename -eq 'Intel(R) Ethernet Connection (7) I219-LM'}| 
            Select-Object devicename, driverversion
    
    If ( ([System.Version]$Driver.Driverversion -ge [System.Version]'12.17.8.9'-and $Model.Model -eq 'Precision 3630 Tower') ) { 
        Write-Output "Version is Current"}
    If ( ([System.Version]$Driver.Driverversion -lt [System.Version]'12.17.8.9'-and $Model.Model -eq 'Precision 3630 Tower') ) { 
            Start-Process -filepath "\\servername\share\share\Dell\Drivers\Dell 3630\Network Card\setup.exe" -ArgumentList '/s' -Wait -NoNewWindow
    } Else {
    Write-Output "Driver Doesn't Exist or Model does not match"
    }

    Again thanks for the help, not sure if you will see this since i marked your response as the answer already.

    Thursday, March 7, 2019 6:44 PM
  • Why don't you print out what these two properties are?

    $Driver.Driverversion
    $Model.Model

    • Edited by JS2010 Thursday, March 7, 2019 7:09 PM
    Thursday, March 7, 2019 7:08 PM
  •  Is this what you are looking for?

    Get-WmiObject Win32_ComputerSystem

    Domain              : domain.com
    Manufacturer        : Dell Inc.
    Model               : Precision 3630 Tower
    Name                : JNameName
    TotalPhysicalMemory : 17050333184

    Get-WmiObject Win32_PnPSignedDriver| select devicename, driverversion | where {$_.devicename -li
    ke 'Intel(R) Ethernet Connection (7) I219-LM'}
    devicename                               driverversion
    ----------                               -------------
    Intel(R) Ethernet Connection (7) I219-LM 12.17.8.9


    • Edited by tech_1000 Thursday, March 7, 2019 7:15 PM
    Thursday, March 7, 2019 7:13 PM
  • How about this way?  Actually, the opposite of "less than" is "greater than or equal to".  So of course you will get both.

    $Model = Get-WmiObject Win32_ComputerSystem | 
      Where-Object model -eq 'Precision 3630 Tower' | 
        Select-Object model
    
    $Driver = Get-WmiObject Win32_PnPSignedDriver | 
      Where-Object devicename -eq 'Intel(R) Ethernet Connection (7) I219-LM' | 
        Select-Object devicename, driverversion
    
    If ( [Version]$Driver.Driverversion -ge '12.17.8.9' -and
    $Model.Model -eq 'Precision 3630 Tower' ) { $Driver.Driverversion $Model.Model 'Version is Current' } If ( [Version]$Driver.Driverversion -lt '12.17.8.9' -and $Model.Model -eq 'Precision 3630 Tower' ) { $filepath = '\\servername\share\share\Dell\Drivers\Dell 3630\Network Card\setup.exe' Start-Process $filepath /s -Wait -NoNewWindow } Else { # -ge 12.17.8.9 $Driver.Driverversion $Model.Model 'Driver Doesn''t Exist or Model does not match, or version is current' }
    • Edited by JS2010 Friday, March 8, 2019 2:31 PM
    Thursday, March 7, 2019 8:59 PM