Category filter
PowerShell script to update drivers on Windows devices
Outdated drivers can cause your Windows devices to run slowly and impact their overall performance. Driver updates can enhance the user experience by fixing bugs and other security issues associated with the older version. The PowerShell script below will download and install any pending driver updates on your Windows device. Using Hexnode’s Execute Custom Script action, you can remotely run custom scripts on your Windows devices without any manual intervention.
Download and install updates for drivers
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
$UpdateSvc = New-Object -ComObject Microsoft.Update.ServiceManager $UpdateSvc.AddService2("7971f918-a847-4430-9279-4a52d1efe18d",7,"") $Session = New-Object -ComObject Microsoft.Update.Session $Searcher = $Session.CreateUpdateSearcher() $Searcher.ServiceID = '7971f918-a847-4430-9279-4a52d1efe18d' $Searcher.SearchScope = 1 # MachineOnly $Searcher.ServerSelection = 3 # Third Party $Criteria = "IsInstalled=0 and Type='Driver'" Write-Host('Searching Driver-Updates...') -Fore Green $SearchResult = $Searcher.Search($Criteria) $Updates = $SearchResult.Updates if([string]::IsNullOrEmpty($Updates)){ Write-Host "No pending driver updates." } else{ #Show available Drivers... $Updates | select Title, DriverModel, DriverVerDate, Driverclass, DriverManufacturer | fl $UpdatesToDownload = New-Object -Com Microsoft.Update.UpdateColl $updates | % { $UpdatesToDownload.Add($_) | out-null } Write-Host('Downloading Drivers...') -Fore Green $UpdateSession = New-Object -Com Microsoft.Update.Session $Downloader = $UpdateSession.CreateUpdateDownloader() $Downloader.Updates = $UpdatesToDownload $Downloader.Download() $UpdatesToInstall = New-Object -Com Microsoft.Update.UpdateColl $updates | % { if($_.IsDownloaded) { $UpdatesToInstall.Add($_) | out-null } } Write-Host('Installing Drivers...') -Fore Green $Installer = $UpdateSession.CreateUpdateInstaller() $Installer.Updates = $UpdatesToInstall $InstallationResult = $Installer.Install() if($InstallationResult.RebootRequired) { Write-Host('Reboot required! Please reboot now.') -Fore Red } else { Write-Host('Done.') -Fore Green } $updateSvc.Services | ? { $_.IsDefaultAUService -eq $false -and $_.ServiceID -eq "7971f918-a847-4430-9279-4a52d1efe18d" } | % { $UpdateSvc.RemoveService($_.ServiceID) } } |
This PowerShell script will download and install all the available driver updates for the Windows device from the Microsoft Update Catalog.
The script will return an output containing the updated drivers’ information on successfully updating them. If no driver updates are available on the Windows device, executing the PowerShell script will return the output: “No pending driver updates.”