41 lines
1.2 KiB
PowerShell
41 lines
1.2 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Updates the running Windows machine.
|
|
#>
|
|
function Update-WindowsInstallation {
|
|
<#
|
|
Runs the Windows update loop.
|
|
#>
|
|
function Start-UpdateLoop {
|
|
$null = Import-Module PSWindowsUpdate;
|
|
$hasUpdates = $false;
|
|
Write-Host "Searching for updates…";
|
|
|
|
while (((Get-WindowsUpdate -IgnoreReboot).Count -gt 0)) {
|
|
Write-Host "There are updates available.";
|
|
Write-Host "Installing updates";
|
|
$hasUpdates = $true;
|
|
|
|
try {
|
|
$null = Install-WindowsUpdate -AcceptAll -IgnoreReboot -ErrorAction "SilentlyContinue";
|
|
}
|
|
catch { }
|
|
|
|
if ((Get-WURebootStatus -Silent)) {
|
|
Write-Host "A Reboot is Required!";
|
|
Write-Host "Windows will reboot now and the installation will be continued automatically.";
|
|
return;
|
|
}
|
|
else {
|
|
Write-Host "Updating Windows finished successfully!";
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (-not $hasUpdates) {
|
|
Write-Host "There are no updates available.";
|
|
}
|
|
}
|
|
|
|
Start-UpdateLoop;
|
|
}
|