Automatically updating all Device Drivers with powershell - Exception HRESULT: 0x80240044

2

I started testing around if i could create a powershell script, which would update all device drivers automatically.

After searching for a while, i stumbled across this thread: How to Automatically update all devices in device manager

The User "HarryMc" pretty much provided me with all the answers needed. My problem now is, that i run into an error on the "Downloading Drivers" and "Installing Drivers" Part.

Powershell throws an HRESULT 0x80240024 exception. The past couple of days i was trying to figure out what might be causing this, but no answer could help me out.

Now i was hoping that maybe here i might be able to get some ideas or answers that could fix the issue.

The Code that i used is:

#search and list all missing Drivers
set Window Title $host.ui.RawUI.WindowTitle = "HarryMc Driver Updater"

$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' and ISHidden=0"
Write-Host('Searching Driver-Updates...') -Fore Green  
$SearchResult = $Searcher.Search($Criteria)          
$Updates = $SearchResult.Updates

#Show available Drivers

$Updates | select Title, DriverModel, DriverVerDate, Driverclass, DriverManufacturer | fl

#Download the Drivers from Microsoft

$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()

#Check if the Drivers are all downloaded and trigger the Installation

$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 }

Write-Host Write-Host('Press any key to exit ...') -Fore Yellow   $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

EDIT: The script fails at line 28 in which it tries to download the drivers, and therefore fails to install them at line 38. Script is being used primarily on win 10 systems.

Thx guys!

drivers
powershell
automation
device-manager
exceptions
asked on Super User Sep 3, 2020 by Suishido • edited Sep 4, 2020 by Suishido

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0