From e1be313fbc3126bbc79fa2fd4b75452e236011b2 Mon Sep 17 00:00:00 2001 From: Bradley Bishop Date: Thu, 13 Dec 2018 15:21:57 -0500 Subject: [PATCH] Feature/priority level for 2008r2 (#27) Fixed the issue with setting the download priority level for windows server 2008r2. The highest setting for Server 2008 r2 is 3 --- update/windows-update.ps1 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/update/windows-update.ps1 b/update/windows-update.ps1 index 865a629..0114fe4 100644 --- a/update/windows-update.ps1 +++ b/update/windows-update.ps1 @@ -146,6 +146,7 @@ function Test-IncludeUpdate($filters, $update) { return $false } +$windowsOsVersion = [System.Environment]::OSVersion.Version $updateSession = New-Object -ComObject 'Microsoft.Update.Session' $updateSession.ClientApplicationID = 'packer-windows-update' @@ -192,7 +193,13 @@ if ($updatesToDownload.Count) { $updateSize = ($updatesToDownloadSize/1024/1024).ToString('0.##') Write-Output "Downloading Windows updates ($($updatesToDownload.Count) updates; $updateSize MB)..." $updateDownloader = $updateSession.CreateUpdateDownloader() - $updateDownloader.Priority = 4 # 1 (dpLow), 2 (dpNormal), 3 (dpHigh), 4 (dpExtraHigh). + # https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_osversioninfoexa#remarks + if (($windowsOsVersion.Major -eq 6 -and $windowsOsVersion.Minor -gt 1) -or ($windowsOsVersion.Major -gt 6)) { + $updateDownloader.Priority = 4 # 1 (dpLow), 2 (dpNormal), 3 (dpHigh), 4 (dpExtraHigh). + } else { + # For versions lower then 6.2 highest prioirty is 3 + $updateDownloader.Priority = 3 # 1 (dpLow), 2 (dpNormal), 3 (dpHigh). + } $updateDownloader.Updates = $updatesToDownload while ($true) { $downloadResult = $updateDownloader.Download()