mattmcspirit / azurestack

Azure Stack Resources
80 stars 41 forks source link

Latest Windows Server Cumulative Update is not being found #135

Closed yellowpanda closed 3 years ago

yellowpanda commented 3 years ago

Describe the issue

In DownloadWinUpdates.ps1 is the following code responsible for finding the latest cumulative update:


$v = "2006"
$buildVersion = "14393"

#...

# Define parameters
Write-Host "Defining StartKB"
if ($v -eq "2019") {
    $StartKB = 'https://support.microsoft.com/en-us/help/4464619'
}
else {
    $StartKB = 'https://support.microsoft.com/en-us/help/4000825'
}
$SearchString = 'Cumulative.*Server.*x64'
Write-Host "StartKB is: $StartKB and Search String is: $SearchString"
# Define the arrays that will be used later
$KBs = @()

#...

# Find the KB Article Number for the latest Windows Server Cumulative Update
Write-Host "Accessing $StartKB to retrieve the list of updates."
$cumulativekbID = (Invoke-WebRequest -Uri $StartKB -UseBasicParsing).RawContent -split "`n"
$cumulativekbID = ($cumulativekbID | Where-Object { $_ -like "*heading*$buildVersion*" } | Select-Object -First 1)
$cumulativekbID = "KB" + ((($cumulativekbID -split "KB", 2)[1]) -split "\s", 2)[0]

if (!$cumulativekbID) {
    Write-Host "No Windows Update KB found - this is an error. Your Windows Server images will be out of date"
}
else {
    $KBs += "$cumulativekbID"
}

#...

Write-Host "List of KBs to download is as follows:"
$kbDisplay = $KBs -join "`r`n"
Write-Host "$kbDisplay"   # <--- Error: Show only "KB"

The script end up assigning "KM" to $KBs. This is not a real KBxxxxxx of cause.

If you open https://support.microsoft.com/en-us/help/4000825 in a browser and search for "Cumulative.Server.x64" then nothing is found.

Hardware N/A.

Send the logs Complete log send to your email.

Relevant log output from Logs2\20210224\WindowsUpdates\WindowsUpdates0224-061829.txt:

Defining StartKB
StartKB is: https://support.microsoft.com/en-us/help/4000825 and Search String is: Cumulative.*Server.*x64
Checking build number to determine Servicing Stack Updates
Getting info for latest Adobe Flash Security Update
Accessing https://support.microsoft.com/en-us/help/4000825 to retrieve the list of updates.
VERBOSE: GET https://support.microsoft.com/en-us/help/4000825 with 0-byte payload
VERBOSE: received -1-byte response of content type text/html; charset=utf-8
List of KBs to download is as follows:
KB5001078
KB4091664
KB

...

List of URLs that will be used for downloading files:
http://download.windowsupdate.com/c/msdownload/update/software/secu/2021/02/windows10.0-kb5001078-x64_6bdd193b6f54fa8d068f031775b1932e26703f73.msu
http://download.windowsupdate.com/d/msdownload/update/software/updt/2018/10/windows10.0-kb4091664-v6-x64_cb6f102b635f103e00988750ca129709212506d6.msu
http://download.windowsupdate.com/c/msdownload/update/software/secu/2019/09/windows10.0-kb4516115-x64_18167dae01da3fd2894274cd9dda650fc5effa55.msu
Update will be stored at C:\AzSPoC\Download\AzSFiles\images\2016\kb5001078-x64.msu
These can be larger than 1GB, so may take a few minutes.
Downloading: http://download.windowsupdate.com/c/msdownload/update/software/secu/2021/02/windows10.0-kb5001078-x64_6bdd193b6f54fa8d068f031775b1932e26703f73.msu
Download took 0 minutes 0 seconds at an average speed of 497.09 Mbit/sec
Update will be stored at C:\AzSPoC\Download\AzSFiles\images\2016\kb4091664-v6-x64.msu
These can be larger than 1GB, so may take a few minutes.
Downloading: http://download.windowsupdate.com/d/msdownload/update/software/updt/2018/10/windows10.0-kb4091664-v6-x64_cb6f102b635f103e00988750ca129709212506d6.msu
Download took 0 minutes 0 seconds at an average speed of 2,875.27 Mbit/sec
Update will be stored at C:\AzSPoC\Download\AzSFiles\images\2016\kb4516115-x64.msu
These can be larger than 1GB, so may take a few minutes.
Downloading: http://download.windowsupdate.com/c/msdownload/update/software/secu/2019/09/windows10.0-kb4516115-x64_18167dae01da3fd2894274cd9dda650fc5effa55.msu
Download took 0 minutes 2 seconds at an average speed of 306.41 Mbit/sec

Additional context By the way, this if-statement will never work because $cumulativekbID will always have at least the value KB

$cumulativekbID = "KB" + ((($cumulativekbID -split "KB", 2)[1]) -split "\s", 2)[0]
if (!$cumulativekbID) {
    Write-Host "No Windows Update KB found - this is an error. Your Windows Server images will be out of date"
}
yellowpanda commented 3 years ago

A nasty side effect is that

Get-KbUpdate -Architecture x64 -OperatingSystem "Windows Server 2016" -Latest -Pattern "KB" -ErrorAction SilentlyContinue -Verbose:$false

takes multiple hours. The DownloadWinUpdates.ps1 takes ~17 hours in my case.

mattmcspirit commented 3 years ago

Thanks - something has obviously changed on the Windows Update feeds side, as you point out, as all of this worked well early in 2020. That said, I'm swamped right now, but will take a look when i can. I'm tempted to simply hard-code the paths to the relevant updates and that way, we know it will work every time, and then it's just a case of updating the path to the new updates on a monthly basis. You only really need the Servicing Stack Update, the latest CU and you're good.

One of the reasons the App Service may be breaking (or taking forever) is it may be trying to apply a CU without the SSU in place already - i know i've seen that in the past.

Feel free to fork the repo and adjust the scripts - i'll look into it too.

mattmcspirit commented 3 years ago

This should now be fixed in the latest release.