Skip to content

Commit

Permalink
Feature/priority level for 2008r2 (#27)
Browse files Browse the repository at this point in the history
Fixed the issue with setting the download priority level for windows server 2008r2. The highest setting for Server 2008 r2 is 3
  • Loading branch information
bishopbm1 authored and rgl committed Dec 13, 2018
1 parent 39e3253 commit e1be313
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion update/windows-update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit e1be313

Please sign in to comment.