From eba9429d79a206cde17b264593d28144c764727c Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Mon, 3 Jul 2023 14:33:55 +0200 Subject: [PATCH] Only perform upgrade as an administrator --- scripts/Windows/OS/Upgrade.ps1 | 46 ++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/scripts/Windows/OS/Upgrade.ps1 b/scripts/Windows/OS/Upgrade.ps1 index e18449c8..40b41a6d 100644 --- a/scripts/Windows/OS/Upgrade.ps1 +++ b/scripts/Windows/OS/Upgrade.ps1 @@ -2,29 +2,31 @@ function Update-WindowsInstallation([Context] $context) { - Write-Host "Upgrading Windows"; - Write-Host "Preparing for Windows Update"; - $null = Import-Module PSWindowsUpdate; + if ($context.GetUACState()) { + Write-Host "Upgrading Windows"; + Write-Host "Preparing for Windows Update"; + $null = Import-Module PSWindowsUpdate; - Write-Host "Performing Windows Update"; - $null = Install-WindowsUpdate -AcceptAll -IgnoreReboot -ErrorAction SilentlyContinue; + Write-Host "Performing Windows Update"; + $null = Install-WindowsUpdate -AcceptAll -IgnoreReboot; - if ((Get-WURebootStatus -Silent -ErrorAction SilentlyContinue)) - { - Write-Information "A Reboot is Required!"; - Write-Information "Windows will reboot now and the installation will be continued automatically."; - $context.Reboot(); - exit; - } - elseif ((Get-WindowsUpdate -IgnoreReboot -ErrorAction SilentlyContinue).Count -gt 0) - { - Write-Information "More updates are available. Restarting upgrade routine."; - $null = Update-WindowsInstallation $context; - return; - } - else - { - Write-Information "Upgrading Windows finished successfully!"; - return; + if ((Get-WURebootStatus -Silent)) + { + Write-Information "A Reboot is Required!"; + Write-Information "Windows will reboot now and the installation will be continued automatically."; + $context.Reboot(); + exit; + } + elseif ((Get-WindowsUpdate -IgnoreReboot).Count -gt 0) + { + Write-Information "More updates are available. Restarting upgrade routine."; + $null = Update-WindowsInstallation $context; + return; + } + else + { + Write-Information "Upgrading Windows finished successfully!"; + return; + } } }