Remotely find missing updates with an offline scan file

Part of our Microsoft Baseline Security Analyzer offering is retrieving a list of missing security updates. Today I would like to share the script to remotely do this in your infrastructure with you.The first step before this script can be executed is downloading the actual cab file that can be used to scan for updates from here: The script which we will examine closer will attempt an automatic download of the cab file.

The second step is downloading the actual script itself, which is hosted on GitHub:

Let's go over this simple script step by step.

    [Parameter(Mandatory = $true)]

    [Parameter(Mandatory = $true, ParameterSetName = 'Path')]

    # As of Sep 2017
    [Parameter(Mandatory = $true, ParameterSetName = 'Url')]

    $UpdateSearchFilter = 'IsHidden = 0',


The parameters should be quite clear. A list of computer names to connect to, either the source path or the download link to the, the update search filter as well as a credential in case Kerberos is not available. If the parameter set 'Url' is chosen, the script will attempt to download the cab file to [System.IO.Path]::GetTempPath().

In general, the script will copy the to all targets first. How long this step takes depends entirely on you: If the administrative share can be accessed, we will use Copy-Item. If it is not available, but the source system has at least WMF5.0 installed and the target system is running at least WMF3 we will make use of the new ToSession parameter of Copy-Item. If all else fails, we will use Lee Holmes' methods Send-File and Write-File to stream the file via WinRM to our targets. These methods range from fastest to slowest in this order.

    $osRoot = Invoke-Command -Session $session -ScriptBlock { $env:SystemDrive } -ErrorAction Stop
    Write-Host ('Error retrieving OS root path from {0}. Assuming issue with the connection. Error was {1}' -f $computer, $_.Exception.Message)
    Write-Error -Message ('Error retrieving OS root path from {0}. Assuming issue with the connection. Error was {1}' -f $computer, $_.Exception.Message)

    $osPSVersion = Invoke-Command -Session $session -ScriptBlock { $PSVersionTable.PSVersion.Major } -ErrorAction Stop
    Write-Host ('Error retrieving OS Powershell version from {0}. Assuming issue with the connection. Error was {1}' -f $computer, $_.Exception.Message)
    Write-Error -Message ('Error retrieving OS Powershell version from {0}. Assuming issue with the connection. Error was {1}' -f $computer, $_.Exception.Message)

$adminShare = '\\{0}\{1}$' -f $computer, ($osRoot -replace '[:\\]')
$useSmb = Test-Path $adminShare

$destination = (Join-Path -Path $osRoot -ChildPath

On the target, a script block is executed. In this block, we instanciate the COM classes Microsoft.Update.Session and Microsoft.Update.ServiceManager and make use of a couple of methods to initiate the offline scan.
First of all, an UpdateManager object is needed that knows the offline scan cab file:

$UpdateService = $UpdateServiceManager.AddScanPackageService("Offline Sync Service", $Destination)

Afterwards an UpdateSearcher will be created with the offline scan repository. Notice here the ServiceID which is set to the GUID of the updater service. The server selection value of three classifies this as an unmanaged server ( ).

$UpdateSearcher = $UpdateSession.CreateUpdateSearcher()
$UpdateSearcher.ServerSelection = 3
$UpdateSearcher.ServiceID = $UpdateService.ServiceID

Lastly, the updates are located by using a search filter:

$SearchResult = $UpdateSearcher.Search($UpdateSearchFilter)
All results are retrieved and will be returned from the script. All in all, you can simply use the script like this:
.\GetMissingUpdates.ps1 -ComputerName serverA,serverB,serverC -Path D:\ -Credential (Get-Credential) -Verbose

Thanks for taking your time and reading all the way to the bottom and enjoy!

Comments (4)

  1. Almost the downloads which miss of the microsoft updates are not microsoft downloads, they are the partners updates if we want to download without missing, we have to avoid the nonne microsoft updates., We have to download the microsoft updates.

  2. Scanning for Security Updates
    You can run Mbsa.exe and Mbsacli.exe with options to verify the presence of security patches.
    Using the Graphical Interface Tool
    The following procedure describes how to use the MBSA GUI tool.
    To use the MBSA GUI tool to scan for updates and patches
    On the Programs menu, click Microsoft Baseline Security Analyzer.
    Click Scan a computer.
    Make sure that the following options are not selected, and then click Start scan.
    Check for Windows administrative vulnerabilities
    Check for weak passwords
    Check for IIS administrative vulnerabilities
    Check for SQL administrative vulnerabilities

Skip to main content