Skip to content

Commit

Permalink
Merge pull request #272 from qmfrederik/fixes/windows-7
Browse files Browse the repository at this point in the history
Windows 7 script improvements
  • Loading branch information
StefanScherer authored Oct 16, 2020
2 parents d007cb7 + c3df3cc commit 45cf498
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 234 deletions.
218 changes: 0 additions & 218 deletions ansible/connection_plugins/packer.py

This file was deleted.

2 changes: 1 addition & 1 deletion ansible/windows_update.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- hosts: all
tasks:
- name: Install only security updates
- name: Install security updates, critical updates and update rollups
win_updates:
category_names:
- SecurityUpdates
Expand Down
2 changes: 1 addition & 1 deletion ansible/windows_update_security_updates.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- hosts: all
tasks:
- name: Install only security updates
- name: Install security updates
win_updates:
category_names:
- SecurityUpdates
Expand Down
14 changes: 13 additions & 1 deletion scripts/win-7-update-2016-convenience-rollup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@ Write-Host "$(Get-Date -Format G): Extracting $update"
Start-Process -FilePath "wusa.exe" -ArgumentList "C:\Updates\$kbid.msu /extract:C:\Updates" -Wait

Write-Host "$(Get-Date -Format G): Installing $update"
Start-Process -FilePath "dism.exe" -ArgumentList "/online /add-package /PackagePath:C:\Updates\$kbid.cab /quiet /norestart /LogPath:C:\Windows\Temp\$kbid.log" -Wait
$process = (Start-Process -FilePath "dism.exe" -ArgumentList "/online /add-package /PackagePath:C:\Updates\$kbid.cab /quiet /norestart /LogPath:C:\Windows\Temp\$kbid.log" -PassThru)

# https://stackoverflow.com/questions/10262231/obtaining-exitcode-using-start-process-and-waitforexit-instead-of-wait#comment71507068_23797762
$handle = $process.Handle # cache proc.Handle

while ($null -eq $process.ExitCode)
{
Write-Host "$(Get-Date -Format G): Convenience rollup update for Windows 7 is still installing (PID $($process.Id))"
Wait-Process -Id $process.Id -Timeout 180 -ErrorAction SilentlyContinue
$process.Refresh()
}

Write-Host "$(Get-Date -Format G): Convenience rollup update for Windows 7 exited with exit code $($process.ExitCode)"

Remove-Item -LiteralPath "C:\Updates" -Force -Recurse
Write-Host "$(Get-Date -Format G): Finished installing $update. The VM will now reboot and continue the installation process."
14 changes: 13 additions & 1 deletion scripts/win-7-update-sp1.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,19 @@ Write-Host "$(Get-Date -Format G): Downloading Windows 7 Service Pack 1"
(New-Object Net.WebClient).DownloadFile("https://download.microsoft.com/download/0/A/F/0AFB5316-3062-494A-AB78-7FB0D4461357/windows6.1-KB976932-X64.exe", "C:\Updates\windows6.1-KB976932-X64.exe")

Write-Host "$(Get-Date -Format G): Installing Windows 7 Service Pack 1"
Start-Process -FilePath "C:\Updates\Windows6.1-KB976932-X64.exe" -ArgumentList "/unattend /nodialog /norestart" -Wait
$process = (Start-Process -FilePath "C:\Updates\Windows6.1-KB976932-X64.exe" -ArgumentList "/unattend /nodialog /norestart" -PassThru)

# https://stackoverflow.com/questions/10262231/obtaining-exitcode-using-start-process-and-waitforexit-instead-of-wait#comment71507068_23797762
$handle = $process.Handle # cache proc.Handle

while ($null -eq $process.ExitCode)
{
Write-Host "$(Get-Date -Format G): Windows 7 Service Pack 1 is still installing (PID $($process.Id))"
Wait-Process -Id $process.Id -Timeout 180 -ErrorAction SilentlyContinue
$process.Refresh()
}

Write-Host "$(Get-Date -Format G): Windows 7 Service Pack 1 exited with exit code $($process.ExitCode)"

Remove-Item -LiteralPath "C:\Updates" -Force -Recurse

Expand Down
18 changes: 6 additions & 12 deletions windows_7.json
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,9 @@
"type": "windows-restart"
},
{
"extra_arguments": [
"--extra-vars",
"ansible_shell_type=powershell ansible_shell_executable=None",
"--connection",
"packer"
],
"user": "vagrant",
"use_proxy": false,
"extra_arguments": ["-e", "ansible_winrm_server_cert_validation=ignore", "-e", "ansible_winrm_scheme=http"],
"playbook_file": "./ansible/windows_update_security_updates.yml",
"type": "ansible"
},
Expand All @@ -211,12 +208,9 @@
"type": "windows-restart"
},
{
"extra_arguments": [
"--extra-vars",
"ansible_shell_type=powershell ansible_shell_executable=None",
"--connection",
"packer"
],
"user": "vagrant",
"use_proxy": false,
"extra_arguments": ["-e", "ansible_winrm_server_cert_validation=ignore", "-e", "ansible_winrm_scheme=http"],
"playbook_file": "./ansible/windows_update.yml",
"type": "ansible"
},
Expand Down

0 comments on commit 45cf498

Please sign in to comment.