Hello,
I am trying to run a powershell script on a Windows Server 2016 to find, download and install updates, but I get the following error:
Exception from HRESULT: 0x80240438
...
+ $result = $updateSearcher.Search("IsInstalled=0 and Type='Software'")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
Here is my script:
Write-Host "Installing WSUS-Updates"
$updateSession = New-Object -Comobject Microsoft.Update.Session
$updateSearcher = $updateSession.CreateUpdateSearcher()
$result = $updateSearcher.Search("IsInstalled=0 and Type='Software'")
if ($result.Updates.Count -eq 0){
Write-Host "No available updates"
exit
}
$updatesToDownload = New-Object -Comobject Microsoft.Update.UpdateColl
foreach ($update in $result.Updates){
$updatesToDownload.Add($update)
}
$downloader = $updateSession.CreateUpdateDownloader()
$downloader.Updates = $updatesToDownload
$downloadResult = $downloader.Download()
$updatesToInstall = New-Object -Comobject Microsoft.Update.UpdateColl
foreach ($update in $result.Updates){
if ($update.IsDownloaded) {$updatesToInstall.Add($update)}
}
$installer = $updateSession.CreateUpdateInstaller()
$installer.Updates = $updatesToInstall
$installationResult = $installer.Install()
exit
I tried running it with admin privileges also, but did not help.
WUServer and WUStatusServer register keys are set to the same path (I read that this may be the problem..)
What could possibly cause the issue?
Thank you in advance!!