2023-07-12 20:37:31 +00:00
|
|
|
#!/bin/pwsh
|
2023-06-25 13:20:58 +00:00
|
|
|
. "$PSScriptRoot/../Scripts/Context.ps1";
|
|
|
|
|
2023-06-30 10:19:54 +00:00
|
|
|
function Update-WindowsInstallation([Context] $context)
|
2023-06-21 20:04:18 +00:00
|
|
|
{
|
2023-07-03 12:34:39 +00:00
|
|
|
if (-not $context.GetUACState()) {
|
2023-07-03 12:33:55 +00:00
|
|
|
Write-Host "Upgrading Windows";
|
|
|
|
Write-Host "Preparing for Windows Update";
|
|
|
|
$null = Import-Module PSWindowsUpdate;
|
2023-06-22 15:18:50 +00:00
|
|
|
|
2023-07-03 12:33:55 +00:00
|
|
|
Write-Host "Performing Windows Update";
|
|
|
|
$null = Install-WindowsUpdate -AcceptAll -IgnoreReboot;
|
2023-06-21 20:04:18 +00:00
|
|
|
|
2023-07-03 12:33:55 +00:00
|
|
|
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;
|
|
|
|
}
|
2023-06-21 20:04:18 +00:00
|
|
|
}
|
|
|
|
}
|