PortValhalla/scripts/Windows/Scripts/Update.ps1

42 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)) {
2024-08-24 12:47:51 +00:00
Write-Host "A Reboot is Required!";
Write-Host "Windows will reboot now and the installation will be continued automatically.";
2024-08-01 00:59:32 +00:00
return;
2024-10-06 19:25:34 +00:00
}
else {
2024-08-24 12:47:51 +00:00
Write-Host "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;
}