2023-06-25 13:20:58 +00:00
|
|
|
. "$PSScriptRoot/../Scripts/Context.ps1";
|
|
|
|
|
2023-06-21 20:04:18 +00:00
|
|
|
function Invoke-Upgrade([Context] $context)
|
|
|
|
{
|
2023-06-22 15:32:36 +00:00
|
|
|
Write-Host "Upgrading Windows";
|
|
|
|
Write-Host "Preparing for Windows Update";
|
2023-06-21 20:04:18 +00:00
|
|
|
$null = Import-Module PSWindowsUpdate;
|
2023-06-22 15:18:50 +00:00
|
|
|
|
2023-06-22 15:32:36 +00:00
|
|
|
Write-Host "Performing Windows Update";
|
2023-06-21 20:04:18 +00:00
|
|
|
$null = Install-WindowsUpdate -AcceptAll -IgnoreReboot;
|
|
|
|
|
2023-06-22 15:32:05 +00:00
|
|
|
if ((Get-WURebootStatus -Silent))
|
2023-06-21 20:04:18 +00:00
|
|
|
{
|
2023-06-22 15:32:36 +00:00
|
|
|
Write-Information "A Reboot is Required!";
|
|
|
|
Write-Information "Windows will reboot now and the installation will be continued automatically.";
|
2023-06-22 20:58:54 +00:00
|
|
|
$context.Reboot();
|
2023-06-21 20:04:18 +00:00
|
|
|
exit;
|
|
|
|
}
|
2023-06-22 15:33:14 +00:00
|
|
|
elseif ((Get-WindowsUpdate -IgnoreReboot).Count -gt 0)
|
2023-06-21 20:04:18 +00:00
|
|
|
{
|
2023-06-22 15:32:36 +00:00
|
|
|
Write-Information "More updates are available. Restarting upgrade routine.";
|
2023-06-21 20:04:18 +00:00
|
|
|
$null = Invoke-Upgrade $context;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-22 15:32:36 +00:00
|
|
|
Write-Information "Upgrading Windows finished successfully!";
|
2023-06-21 20:04:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|