Trying to use powershell in place of MBSA RRS feed

  • Question

  • I have the script running but it keeps crashing. below is what I have:

    #Using WUA to Scan for Updates Offline with PowerShell 
    #VBS version:  
    $UpdateSession = New-Object -ComObject Microsoft.Update.Session 
    $UpdateServiceManager  = New-Object -ComObject Microsoft.Update.ServiceManager 
    $UpdateService = $UpdateServiceManager.AddScanPackageService("Offline Sync Service", "c:\temp\", 1) 
    $UpdateSearcher = $UpdateSession.CreateUpdateSearcher()   
    Write-Output "Searching for updates... `r`n"  
    $UpdateSearcher.ServerSelection = 3 #ssOthers  
    $UpdateSearcher.ServiceID = $UpdateService.ServiceID  
    $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 `r`n"  
    $i = 0 foreach($Update in $Updates){ 
         Write-Output "$($i)> $($Update.Title)"     

    this is the output error im seeing:

    PS C:\WINDOWS\system32> C:\Temp\Scan-UpdatesOffline.ps1
    Searching for updates...

    The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
    At C:\Temp\Scan-UpdatesOffline.ps1:15 char:1
    + $SearchResult = $UpdateSearcher.Search("IsInstalled=0")
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : OperationStopped: (:) [], FileNotFoundException
        + FullyQualifiedErrorId : System.IO.FileNotFoundException
    There are no applicable updates.

    Thanks, Matt

    Thursday, June 6, 2019 8:43 PM