From 6138ad7ffa985dbea51bf7a293942e447ed5b351 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Fri, 16 Jun 2023 20:10:34 +0200 Subject: [PATCH] Add a script for installing windows updates --- scripts/Windows/OS/Setup.ps1 | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 scripts/Windows/OS/Setup.ps1 diff --git a/scripts/Windows/OS/Setup.ps1 b/scripts/Windows/OS/Setup.ps1 new file mode 100644 index 00000000..26c5dff6 --- /dev/null +++ b/scripts/Windows/OS/Setup.ps1 @@ -0,0 +1,33 @@ +foreach ($module in @("PSWindowsUpdate")) +{ + if (-not (Get-Module $module)) + { + Install-Module -AcceptLicense -Force "$module"; + } +} + +Import-Module PSWindowsUpdate; +Import-Module ScheduledTasks; + +$installerPath = "$PSScriptRoot/Manage.ps1"; +$setupPath = "$($MyInvocation.MyCommand.Path)"; + +Install-WindowsUpdate -AcceptAll -IgnoreReboot; + +if ((Get-WindowsUpdate).Count -gt 0) +{ + $nextScript = "$setupPath"; +} +else +{ + $nextScript = "$installerPath"; +} + +if ((Get-WURebootStatus).RebootRequired) +{ + New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\RunOnce" -Name "PortValhalla" -Value "pwsh `"$nextScript`"" -PropertyType ExpandString; +} +else +{ + . "$nextScript"; +}