PortValhalla/scripts/Windows/OS/Upgrade.ps1

30 lines
1,006 B
PowerShell

. "$PSScriptRoot/../Scripts/Context.ps1";
function Update-WindowsInstallation([Context] $context)
{
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;
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;
}
}