Author Posts

January 22, 2016 at 6:41 pm

Hi,

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?

http://deploywindows.info/2015/01/22/automate-mbsa-scan-and-download-missing-patches/

 
    $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
    }
    else
    {
    $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
    Write-Host
    }
    }

    Write-Host
    }
 

January 25, 2016 at 12:12 pm

This line:

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

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