Search code examples
powershelldriver

PowerShell To update Drivers of a computer


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.

I posted my question on technet as well.

https://social.technet.microsoft.com/Forums/windowsserver/en-US/249a930f-0989-4734-bd8b-f30bbbc838ca/powershell-to-update-drivers-of-a-computer?forum=winserverpowershell#445d46ff-aa29-4960-9258-e7504a643aa6


Solution

  • Your script selects the drivers, but then does nothing with the result..

    I think this should do it:

    Get-WmiObject Win32_PnPSignedDriver | 
        Where-Object {$_.devicename -eq 'Intel(R) Ethernet Connection (7) I219-LM'} |
        ForEach-Object {
            if ([Version]$_.Driverversion -ge [Version]'12.17.8.9') {  
                Write-Output "Version is Current"
                # return from a function ?
                # return 0
                # exit script with exitcode?
                # exit 0
            } 
            else {
                Start-Process -FilePath "\\servername\share\share\Dell\Drivers\Dell 3630\Network Card\setup.exe" -ArgumentList '/s' -Wait -NoNewWindow
            }
        }
    

    I have also altered the check on the driver version by casting the strings to System.Version objects. That way the comparison will be correct as opposed to comparing strings.