PortValhalla/scripts/Windows/OS/Upgrade.ps1

40 lines
1.2 KiB
PowerShell
Raw Normal View History

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()) {
Write-Host "Upgrading Windows";
Write-Host "Preparing for Windows Update";
$null = Import-Module PSWindowsUpdate;
2023-06-22 15:18:50 +00:00
Write-Host "Performing Windows Update";
2023-07-18 19:57:08 +00:00
try {
$null = Install-WindowsUpdate -AcceptAll -IgnoreReboot -ErrorAction "SilentlyContinue";
}
catch { }
2023-06-21 20:04:18 +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;
}
2023-07-15 23:22:43 +00:00
elseif (
((Get-WindowsUpdate -IgnoreReboot).Count -gt 0) -and
((Get-WindowsUpdate -IgnoreReboot).KB -ne "KB2267602"))
{
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
}
}