PortValhalla/scripts/Windows/OS/Upgrade.ps1

30 lines
1,017 B
PowerShell
Raw Normal View History

2023-06-21 20:04:18 +00:00
function Invoke-Upgrade([Context] $context)
{
2023-06-22 15:18:50 +00:00
Write-Information "Upgrading Windows";
Write-Information "Preparing for Windows Update";
2023-06-21 20:04:18 +00:00
$null = Import-Module PSWindowsUpdate;
2023-06-22 15:18:50 +00:00
Write-Information "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:18:50 +00:00
Write-Debug "A Reboot is Required!";
Write-Debug "Windows will reboot now and the installation will be continued automatically.";
2023-06-21 20:04:18 +00:00
$null = New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\RunOnce" -Name "PortValhalla" -Value "pwsh `"$($context.EntryPoint)`"" -PropertyType ExpandString;
2023-06-22 15:19:00 +00:00
Restart-Computer;
2023-06-21 20:04:18 +00:00
exit;
}
elseif ((Get-WindowsUpdate).Count -gt 0)
{
2023-06-22 15:18:50 +00:00
Write-Debug "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:18:50 +00:00
Write-Host "Upgrading Windows finished successfully!";
2023-06-21 20:04:18 +00:00
return;
}
}