Only perform upgrade as an administrator

This commit is contained in:
Manuel Thalmann 2023-07-03 14:33:55 +02:00
parent 0996dbecaf
commit eba9429d79

View file

@ -2,21 +2,22 @@
function Update-WindowsInstallation([Context] $context)
{
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;
$null = Install-WindowsUpdate -AcceptAll -IgnoreReboot;
if ((Get-WURebootStatus -Silent -ErrorAction SilentlyContinue))
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 -ErrorAction SilentlyContinue).Count -gt 0)
elseif ((Get-WindowsUpdate -IgnoreReboot).Count -gt 0)
{
Write-Information "More updates are available. Restarting upgrade routine.";
$null = Update-WindowsInstallation $context;
@ -27,4 +28,5 @@ function Update-WindowsInstallation([Context] $context)
Write-Information "Upgrading Windows finished successfully!";
return;
}
}
}