WSUS Updates Powershell script fails; Errorcode: 80240438 RRS feed

  • Question

  • 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" 



    $updatesToDownload = New-Object -Comobject Microsoft.Update.UpdateColl

    foreach ($update in $result.Updates){



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


    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!!

    Friday, November 30, 2018 12:11 PM

All replies

  • Run the troubleshooter and see if it finds any errors. 

    I've found that this query runs faster. You could try that.

    $objResults = $objSearcher.Search("IsAssigned=1 and IsHidden=0 and IsInstalled=0 and Type='Software'") 

    Friday, November 30, 2018 3:40 PM
  • Unfortunately this query did not solve the problem. It seems that the $result is a null object...

    When I ran the troubleshooter I got this:

    Potential Windows Update Database error detected

    Any ideas how to fix it?

    Monday, December 3, 2018 8:14 AM
  • The DISM tool.


    Dism /Online /Cleanup-Image /CheckHealth
    Dism /Online /Cleanup-Image /ScanHealth
    Dism /online /cleanup-image /analyzecomponentstore
    Dism /Online /Cleanup-Image /restoreHealth

    Monday, December 3, 2018 11:57 PM