Scan-UpdatesOffline.ps1
<#PSScriptInfo .VERSION 2.0 .GUID 74fe57bb-886a-493a-81f7-5b4af96903c4 .AUTHOR Andrei Stoica astoica@microsoft.com .COMPANYNAME Microsoft Corporation .COPYRIGHT .TAGS .LICENSEURI https://opensource.org/licenses/MIT .PROJECTURI .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES VBS version: https://learn.microsoft.com/en-us/windows/win32/wua_sdk/using-wua-to-scan-for-updates-offline #> <# .DESCRIPTION Using WUA to Scan for Updates Offline with PowerShell #> Param() $UpdateSession = New-Object -ComObject Microsoft.Update.Session $UpdateServiceManager = New-Object -ComObject Microsoft.Update.ServiceManager $UpdateService = $UpdateServiceManager.AddScanPackageService("Offline Sync Service", "c:\temp\wsusscn2.cab") $UpdateSearcher = $UpdateSession.CreateUpdateSearcher() Write-Output "Searching for updates... `r`n" $UpdateSearcher.ServerSelection = 3 #ssOthers #IncludePotentiallySupersededUpdates = $true is good for older OSes, to include Security-Only or superseded updates in the result list, otherwise these are pruned out and not returned as part of the final result list $UpdateSearcher.IncludePotentiallySupersededUpdates = $false $UpdateSearcher.ServiceID = $UpdateService.ServiceID.ToString() $SearchResult = $UpdateSearcher.Search("IsInstalled=0") #or "IsInstalled=0 or IsInstalled=1" to also list the installed updates as MBSA did $Updates = $SearchResult.Updates if($Updates.Count -eq 0){ Write-Output "There are no applicable updates." return $null } Write-Output "List of applicable items on the machine when using wssuscan.cab: `r`n" $i = 0 foreach($Update in $Updates){ Write-Output "$($i)> $($Update.Title)" $i++ } |