PortValhalla/scripts/Windows/OS/Setup.ps1

33 lines
714 B
PowerShell

foreach ($module in @("PSWindowsUpdate"))
{
if (-not (Get-Module $module))
{
Install-Module -AcceptLicense -Force "$module";
}
}
Import-Module PSWindowsUpdate;
Import-Module ScheduledTasks;
$installerPath = "$PSScriptRoot/Install.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";
}