Add scripts for updating windows
This commit is contained in:
parent
ee077e0765
commit
12c449eb7c
|
@ -2,13 +2,13 @@
|
|||
. "$PSScriptRoot/../Scripts/Prerequisites.ps1";
|
||||
|
||||
. "$PSScriptRoot/Manage.ps1";
|
||||
. "$PSScriptRoot/Upgrade.ps1";
|
||||
. "$PSScriptRoot/User/Install.ps1";
|
||||
. "$PSScriptRoot/../Scripts/Choco.ps1";
|
||||
. "$PSScriptRoot/../Scripts/Context.ps1";
|
||||
. "$PSScriptRoot/../Scripts/Hooks.ps1";
|
||||
. "$PSScriptRoot/../Scripts/PowerManagement.ps1";
|
||||
. "$PSScriptRoot/../Scripts/SetupConfig.ps1";
|
||||
. "$PSScriptRoot/../Scripts/Update.ps1";
|
||||
. "$PSScriptRoot/../Software/Firefox/Install.ps1";
|
||||
|
||||
<#
|
||||
|
@ -24,15 +24,9 @@ function Start-WindowsInstallation {
|
|||
Starts the installation loop.
|
||||
#>
|
||||
function Start-InstallationLoop {
|
||||
. "$PSScriptRoot/../Scripts/Choco.ps1";
|
||||
. "$PSScriptRoot/../Scripts/Hooks.ps1";
|
||||
. "$PSScriptRoot/../Scripts/PowerManagement.ps1";
|
||||
. "$PSScriptRoot/../Scripts/SetupConfig.ps1";
|
||||
|
||||
while (-not (Get-IsFinished)) {
|
||||
if (-not (Get-Stage)) {
|
||||
Set-Stage [SetupStage]::Initialize;
|
||||
break;
|
||||
if ($null -eq (Get-Stage)) {
|
||||
Set-Stage ([SetupStage]::Initialize);
|
||||
} elseif ((Get-Stage) -eq ([SetupStage]::Initialize)) {
|
||||
if (-not ((Get-Command "choco") -and (Get-Command "refreshenv"))) {
|
||||
Invoke-Hook "Install-Chocolatey" -Fallback {
|
||||
|
@ -53,12 +47,30 @@ function Start-InstallationLoop {
|
|||
return;
|
||||
}
|
||||
|
||||
Invoke-Hook "Install-PSModules" -Fallback {
|
||||
Install-Module -AcceptLicense -Force PSWindowsUpdate;
|
||||
};
|
||||
|
||||
if (Test-Path $env:PWSH_PATH) {
|
||||
Remove-Item -Recurse $env:PWSH_PATH;
|
||||
attrib "-R" "$env:PWSH_PATH\*" /S /D;
|
||||
Remove-Item -Recurse -Force $env:PWSH_PATH;
|
||||
} else {
|
||||
Set-Stage ([SetupStage]::Install);
|
||||
}
|
||||
} else {
|
||||
$null = Import-Module PSWindowsUpdate;
|
||||
|
||||
Invoke-Hook "Invoke-WindowsUpdate" -Fallback {
|
||||
Update-WindowsInstallation;
|
||||
};
|
||||
|
||||
if ((Get-WURebootStatus -Silent)) {
|
||||
Restart-Intermediate;
|
||||
return;
|
||||
}
|
||||
|
||||
switch (Get-Stage) {
|
||||
$null {
|
||||
([SetupStage]::Install) {
|
||||
}
|
||||
Default {}
|
||||
}
|
||||
|
@ -74,6 +86,7 @@ function Invoke-WindowsInstallation([Context] $context) {
|
|||
}
|
||||
|
||||
function Start-OldWindowsInstallationScript([Context] $context) {
|
||||
. "$PSScriptRoot/Upgrade.ps1";
|
||||
$finished = $false;
|
||||
Remove-Item Env:\POSH_THEME -ErrorAction SilentlyContinue;
|
||||
$configPath = "$PSScriptRoot/../Config";
|
||||
|
|
34
scripts/Windows/Scripts/Update.ps1
Normal file
34
scripts/Windows/Scripts/Update.ps1
Normal file
|
@ -0,0 +1,34 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Updates the running Windows machine.
|
||||
#>
|
||||
function Update-WindowsInstallation {
|
||||
<#
|
||||
Runs the Windows update loop.
|
||||
#>
|
||||
function Start-UpdateLoop {
|
||||
Write-Host "Preparing for Windows Update";
|
||||
$null = Import-Module PSWindowsUpdate;
|
||||
|
||||
while (((Get-WindowsUpdate -IgnoreReboot).Count -gt 0)) {
|
||||
Write-Host "There are updates available.";
|
||||
Write-Host "Installing updates";
|
||||
|
||||
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;
|
||||
}
|
||||
} else {
|
||||
Write-Information "Upgrading Windows finished successfully!";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Start-UpdateLoop;
|
||||
}
|
Loading…
Reference in a new issue