From 1a164c38ddc577cfc29e2fc826c741aee1ccc853 Mon Sep 17 00:00:00 2001 From: Jeff Weiner Date: Mon, 22 Jun 2020 01:25:04 -0700 Subject: [PATCH] Install-WindowsUpdates fixes (#1071) --- images/win/Windows2016-Azure.json | 18 ++++++++++++------ images/win/Windows2019-Azure.json | 18 ++++++++++++------ .../Installers/Install-WindowsUpdates.ps1 | 3 +-- .../SoftwareReport/SoftwareReport.Common.psm1 | 5 ++--- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/images/win/Windows2016-Azure.json b/images/win/Windows2016-Azure.json index 2f4bc5103..af9bb028b 100644 --- a/images/win/Windows2016-Azure.json +++ b/images/win/Windows2016-Azure.json @@ -552,12 +552,6 @@ "{{ template_dir }}/scripts/Installers/Install-DotnetSDK.ps1" ] }, - { - "type": "powershell", - "scripts":[ - "{{ template_dir }}/scripts/Installers/Install-WindowsUpdates.ps1" - ] - }, { "type": "windows-shell", "inline": ["wmic product where \"name like '%%microsoft azure powershell%%'\" call uninstall /nointeractive"] @@ -1010,6 +1004,18 @@ "{{ template_dir }}/scripts/Installers/Validate-DiskSpace.ps1" ] }, + { + "type": "powershell", + "scripts":[ + "{{ template_dir }}/scripts/Installers/Install-WindowsUpdates.ps1" + ], + "elevated_user": "{{user `install_user`}}", + "elevated_password": "{{user `install_password`}}" + }, + { + "type": "windows-restart", + "restart_timeout": "10m" + }, { "type": "powershell", "inline": [ diff --git a/images/win/Windows2019-Azure.json b/images/win/Windows2019-Azure.json index d851dc9e1..6651f1c07 100644 --- a/images/win/Windows2019-Azure.json +++ b/images/win/Windows2019-Azure.json @@ -513,12 +513,6 @@ "{{ template_dir }}/scripts/Installers/Install-DotnetSDK.ps1" ] }, - { - "type": "powershell", - "scripts":[ - "{{ template_dir }}/scripts/Installers/Install-WindowsUpdates.ps1" - ] - }, { "type": "windows-shell", "inline": ["wmic product where \"name like '%%microsoft azure powershell%%'\" call uninstall /nointeractive"] @@ -1001,6 +995,18 @@ "{{ template_dir }}/scripts/Installers/Validate-DiskSpace.ps1" ] }, + { + "type": "powershell", + "scripts":[ + "{{ template_dir }}/scripts/Installers/Install-WindowsUpdates.ps1" + ], + "elevated_user": "{{user `install_user`}}", + "elevated_password": "{{user `install_password`}}" + }, + { + "type": "windows-restart", + "restart_timeout": "10m" + }, { "type": "powershell", "inline": [ diff --git a/images/win/scripts/Installers/Install-WindowsUpdates.ps1 b/images/win/scripts/Installers/Install-WindowsUpdates.ps1 index eec8ef0d7..a57594d9d 100644 --- a/images/win/scripts/Installers/Install-WindowsUpdates.ps1 +++ b/images/win/scripts/Installers/Install-WindowsUpdates.ps1 @@ -1,10 +1,9 @@ ################################################################################ ## File: Install-WindowsUpdates.ps1 ## Desc: Install Windows Updates. -## Should be run at end just before Antivirus. +## Should be run at end, just before SoftwareReport and Finalize-VM.ps1. ################################################################################ Write-Host "Run windows updates" Install-Module -Name PSWindowsUpdate -Force -AllowClobber -Get-WUInstall -WindowsUpdate -AcceptAll -Install -UpdateType Software -IgnoreReboot Get-WUInstall -MicrosoftUpdate -AcceptAll -Install -IgnoreUserInput -IgnoreReboot diff --git a/images/win/scripts/SoftwareReport/SoftwareReport.Common.psm1 b/images/win/scripts/SoftwareReport/SoftwareReport.Common.psm1 index 6f087bdb0..829ac4657 100644 --- a/images/win/scripts/SoftwareReport/SoftwareReport.Common.psm1 +++ b/images/win/scripts/SoftwareReport/SoftwareReport.Common.psm1 @@ -3,9 +3,8 @@ function Get-OSName { } function Get-OSVersion { - $systemInfo = Get-CimInstance -ClassName Win32_OperatingSystem - $OSVersion = $systemInfo.Version - $OSBuild = $systemInfo.BuildNumber + $OSVersion = (Get-CimInstance -ClassName Win32_OperatingSystem).Version + $OSBuild = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion' UBR).UBR return "OS Version: $OSVersion Build $OSBuild" }