Only perform upgrade as an administrator
This commit is contained in:
parent
0996dbecaf
commit
eba9429d79
1 changed files with 24 additions and 22 deletions
|
@ -2,29 +2,31 @@
|
||||||
|
|
||||||
function Update-WindowsInstallation([Context] $context)
|
function Update-WindowsInstallation([Context] $context)
|
||||||
{
|
{
|
||||||
Write-Host "Upgrading Windows";
|
if ($context.GetUACState()) {
|
||||||
Write-Host "Preparing for Windows Update";
|
Write-Host "Upgrading Windows";
|
||||||
$null = Import-Module PSWindowsUpdate;
|
Write-Host "Preparing for Windows Update";
|
||||||
|
$null = Import-Module PSWindowsUpdate;
|
||||||
|
|
||||||
Write-Host "Performing Windows Update";
|
Write-Host "Performing Windows Update";
|
||||||
$null = Install-WindowsUpdate -AcceptAll -IgnoreReboot -ErrorAction SilentlyContinue;
|
$null = Install-WindowsUpdate -AcceptAll -IgnoreReboot;
|
||||||
|
|
||||||
if ((Get-WURebootStatus -Silent -ErrorAction SilentlyContinue))
|
if ((Get-WURebootStatus -Silent))
|
||||||
{
|
{
|
||||||
Write-Information "A Reboot is Required!";
|
Write-Information "A Reboot is Required!";
|
||||||
Write-Information "Windows will reboot now and the installation will be continued automatically.";
|
Write-Information "Windows will reboot now and the installation will be continued automatically.";
|
||||||
$context.Reboot();
|
$context.Reboot();
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
elseif ((Get-WindowsUpdate -IgnoreReboot -ErrorAction SilentlyContinue).Count -gt 0)
|
elseif ((Get-WindowsUpdate -IgnoreReboot).Count -gt 0)
|
||||||
{
|
{
|
||||||
Write-Information "More updates are available. Restarting upgrade routine.";
|
Write-Information "More updates are available. Restarting upgrade routine.";
|
||||||
$null = Update-WindowsInstallation $context;
|
$null = Update-WindowsInstallation $context;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Write-Information "Upgrading Windows finished successfully!";
|
Write-Information "Upgrading Windows finished successfully!";
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue