PortValhalla/scripts/Windows/OS/Upgrade.ps1

30 lines
1 KiB
PowerShell
Raw Normal View History

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-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;
}
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;
}
}