Forum Discussion

annkis's avatar
annkis
Copper Contributor
Nov 06, 2023

Download and Install Windows Updates offline using the wsusscn2.cab file and Windows Update API

Hi, 

I'm trying to find a way to install Windows Updates (CAB files) on offline Windows 10 V1809 computers.

Overall the process I'm trying to automate is:

1. Scan for missing Windows Updates on the computer and download all missing Windows Updates 

2. On an offline computer - install the Updates. 

I'm using the wsusscn2.cab file as described here: 
https://learn.microsoft.com/en-us/windows/win32/wua_sdk/using-wua-to-scan-for-updates-offline 

to search the updates, download them, and then try to install them.

I manage to search and download the updates, but I encounter this error when trying to install:

When -2145124318 in Hex is: 0x80240022

This error code = WU_E_ALL_UPDATES_FAILED

Operation failed for all the updates.

 

How can I fix my code to successfully install this updates? 

 

Here is the code I'm using:

 

#Search for Windows Updates:

 

# Load the Windows Update Agent COM object
$UpdateSession = New-Object -ComObject Microsoft.Update.Session
$UpdateServiceManager = New-Object -ComObject Microsoft.Update.ServiceManager

#Load the wsusscn2.cab file that enables offline Updates instllation:
$UpdateService = $UpdateServiceManager.AddScanPackageService("Offline Sync Service", "c:\wsusscn2.cab")

# Create a searcher for available updates
$UpdateSearcher = $UpdateSession.CreateUpdateSearcher()


# Search for updates in the SoftwareDistribution folder:
#The ServerSelection enumeration defines values that describe the type of server to use for an update search operation.
# ssOthers: Search another server, to be specified by other means
$updateSearcher.ServerSelection = 3 # ssOthers
$UpdateSearcher.ServiceID = $UpdateService.ServiceID
$Criteria = "IsInstalled=0 and Type='Software'"
$SearchResult = $UpdateSearcher.Search($Criteria)
$Updates = $SearchResult.Updates

if ($SearchResult.Updates.Count -eq 0) {
write-Host "There are no applicable updates"
}

 

#Download the Windows Updates (to SoftwareDistribution): 

 

$SearchResult = $Updates
# Create a Windows Update Session
$Session = New-Object -ComObject Microsoft.Update.Session
# Create a Windows Update Downloader:
$Downloader = $Session.CreateUpdateDownloader()
$Downloader.Updates = $SearchResult
#Download updates to C:\Windows\SoftwareDistribution
$Downloader.Download()

 

#Install the Windows Updates from SoftwareDistribution:

# Create the Installer Object:
$installer = New-Object -ComObject Microsoft.Update.Installer
$Installer.Updates = $Updates
#Install updates:
$Result = $Installer.Install()

 

Thanks,

Ann 

No RepliesBe the first to reply

Resources