Script to automate MBSA scan and download missing patches

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 9 months ago.

  • Author
  • #34212
    Profile photo of Brian


    Not a PowerShell guy so go easy on me here. I just found a script that I would like to use. This script scans for missing patches via MS's MBSA, downloads them and then generates a batch file to install the missing ones. Issue I am having is the command that downloads the patches doesn't download anything. The author of the script has closed what he wrote on his site from future comment. Any ideas?

        $UpdateXML = “updates.xml”
        $toFolder = “c:\temp\”
        $installFile = $toFolder +”\_Install.bat”
        #Initialize webclient for downloading files
        $webclient = New-Object Net.Webclient
        $webClient.UseDefaultCredentials = $true
        # Get the content of the XML file
        $Updates = [xml](Get-Content $UpdateXML)
        “@Echo Off” | Out-File $installFile
        “REM This will install all patches” | Out-File $installFile -Append
        foreach ($Check in $Updates.XMLOut.Check)
        Write-Host “Checking for”, $Check.Name
        Write-Host $Check.Advice.ToString()
        #Checking for files to download
        foreach ($UpdateData in $Check.Detail.UpdateData)
        if ($UpdateData.IsInstalled -eq $false)
        Write-Host “Download the file for KB”, $UpdateData.KBID
        Write-Host “Starting download “, $UpdateData.Title, “.”
        $url = [URI]$UpdateData.References.DownloadURL
        $fileName = $url.Segments[$url.Segments.Count – 1]
        $toFile = $toFolder +”\”+ $fileName
        #$webClient.DownloadFile($url, $toFile)
        Write-Host “Done downloading”
        “@ECHO Starting installing “+ $fileName | Out-File $installFile -Append
        if ($fileName.EndsWith(“.msu”))
        “wusa.exe “+ $fileName + ” /quiet /norestart /log:%SystemRoot%\Temp\KB”+$UpdateData.KBID+”.log” | Out-File $installFile -Append
        elseif ($fileName.EndsWith(“.cab”))
        “start /wait pkgmgr.exe /ip /m:”+ $fileName + ” /quiet /nostart /l:%SystemRoot%\Temp\KB”+$UpdateData.KBID+”.log” | Out-File $installFile -Append
        $fileName + ” /passive /norestart /log %SystemRoot%\Temp\KB”+$UpdateData.KBID+”.log” | Out-File $installFile -Append
        “@ECHO Installation returned %ERRORLEVEL%” | Out-File $installFile -Append
        “@ECHO.” | Out-File $installFile -Append
  • #34268
    Profile photo of Don Jones
    Don Jones

    This line:

    #$webClient.DownloadFile($url, $toFile)

    Is commented out. I would assume that's relevant?

You must be logged in to reply to this topic.