PortValhalla/scripts/Windows/Scripts/Update.ps1

41 lines
1.2 KiB
PowerShell
Raw Normal View History

2024-08-01 00:59:32 +00:00
<#
.SYNOPSIS
Updates the running Windows machine.
#>
function Update-WindowsInstallation {
<#
Runs the Windows update loop.
#>
function Start-UpdateLoop {
$null = Import-Module PSWindowsUpdate;
2024-08-18 10:20:21 +00:00
$hasUpdates = $false;
Write-Host "Searching for updates…";
2024-08-01 00:59:32 +00:00
while (((Get-WindowsUpdate -IgnoreReboot).Count -gt 0)) {
Write-Host "There are updates available.";
Write-Host "Installing updates";
2024-08-18 10:20:21 +00:00
$hasUpdates = $true;
2024-08-01 00:59:32 +00:00
try {
$null = Install-WindowsUpdate -AcceptAll -IgnoreReboot -ErrorAction "SilentlyContinue";
}
catch { }
if ((Get-WURebootStatus -Silent)) {
Write-Information "A Reboot is Required!";
Write-Information "Windows will reboot now and the installation will be continued automatically.";
return;
2024-08-01 10:31:25 +00:00
} else {
2024-08-01 10:32:43 +00:00
Write-Information "Updating Windows finished successfully!";
2024-08-01 10:31:25 +00:00
return;
2024-08-01 00:59:32 +00:00
}
}
2024-08-18 10:20:21 +00:00
if (-not $hasUpdates) {
Write-Host "There are no updates available.";
}
2024-08-01 00:59:32 +00:00
}
Start-UpdateLoop;
}