Commit fe05efa1 authored by Ken Sykora's avatar Ken Sykora

Potential fix for Windows 7 issue where updates weren't running due to an...

Potential fix for Windows 7 issue where updates weren't running due to an error being thrown in the update script. Added error handling to retry network issues. joefitzgerald/packer-windows#83
parent 2e309b58
......@@ -243,6 +243,13 @@
-->
<!-- END WITHOUT WINDOWS UPDATES -->
<!-- WITH WINDOWS UPDATES -->
<!-- Disable automatic updates so the system update process doesn't interfere with the update script -->
<SynchronousCommand wcm:action="add">
<CommandLine>cmd.exe /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File a:\dis-updates.ps1 -AutoStart</CommandLine>
<Description>Install OpenSSH</Description>
<Order>99</Order>
<RequiresUserInput>true</RequiresUserInput>
</SynchronousCommand>
<SynchronousCommand wcm:action="add">
<CommandLine>cmd.exe /c a:\microsoft-updates.bat</CommandLine>
<Order>98</Order>
......
......@@ -143,7 +143,20 @@ function Check-WindowsUpdates() {
Write-Host $Message
$script:UpdateSearcher = $script:UpdateSession.CreateUpdateSearcher()
$script:SearchResult = $script:UpdateSearcher.Search("IsInstalled=0 and Type='Software' and IsHidden=0")
$script:successful = $FALSE
$script:attempts = 0
$script:maxAttempts = 12
while(-not $script:successful -and $script:attempts -lt $script:maxAttempts) {
try {
$script:SearchResult = $script:UpdateSearcher.Search("IsInstalled=0 and Type='Software' and IsHidden=0")
$script:successful = $TRUE
} catch {
Write-Error "Search call to UpdateSearcher was unsuccessful. Retrying in 10s."
$script:attempts = $script:attempts + 1
Start-Sleep -s 10
}
}
if ($SearchResult.Updates.Count -ne 0) {
$script:SearchResult.Updates |Select-Object -Property Title, Description, SupportUrl, UninstallationNotes, RebootRequired, EulaAccepted |Format-List
$global:MoreUpdates=1
......
......@@ -18,6 +18,7 @@
"vnc_port_max": 5980,
"floppy_files": [
"./answer_files/7/Autounattend.xml",
"./scripts/dis-updates.ps1",
"./scripts/microsoft-updates.bat",
"./scripts/win-updates.ps1",
"./scripts/openssh.ps1"
......@@ -45,6 +46,7 @@
"disk_size": 61440,
"floppy_files": [
"./answer_files/7/Autounattend.xml",
"./scripts/dis-updates.ps1",
"./scripts/microsoft-updates.bat",
"./scripts/win-updates.ps1",
"./scripts/openssh.ps1",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment