PortValhalla/scripts/Windows/OS/Upgrade.ps1

30 lines
1 KiB
PowerShell

function Invoke-Upgrade([Context] $context)
{
Write-Information "Upgrading Windows";
Write-Information "Preparing for Windows Update";
$null = Import-Module PSWindowsUpdate;
Write-Information "Performing Windows Update";
$null = Install-WindowsUpdate -AcceptAll -IgnoreReboot;
if ((Get-WURebootStatus).RebootRequired)
{
Write-Debug "A Reboot is Required!";
Write-Debug "Windows will reboot now and the installation will be continued automatically.";
$null = New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\RunOnce" -Name "PortValhalla" -Value "pwsh `"$($context.EntryPoint)`"" -PropertyType ExpandString;
Restart-Computer;
exit;
}
elseif ((Get-WindowsUpdate).Count -gt 0)
{
Write-Debug "More updates are available. Restarting upgrade routine.";
$null = Invoke-Upgrade $context;
return;
}
else
{
Write-Host "Upgrading Windows finished successfully!";
return;
}
}