diff --git a/scripts/Windows/Scripts/PowerManagement.ps1 b/scripts/Windows/Scripts/PowerManagement.ps1 index 6c361b34..70c7fb8f 100644 --- a/scripts/Windows/Scripts/PowerManagement.ps1 +++ b/scripts/Windows/Scripts/PowerManagement.ps1 @@ -38,6 +38,32 @@ $null = New-Module { } } + <# + .SYNOPSIS + Generates a script for executing the installer. + #> + function Get-StartupScript { + "pwsh " + (Get-StartupArguments); + } + + <# + .SYNOPSIS + Generates arguments for running the installer using `pwsh`. + #> + function Get-StartupArguments { + "-Command " + + (& { + if ($env:PWSH_PATH) { + "`$env:PWSH_PATH = $(ConvertTo-Injection $env:PWSH_PATH);" + } else { + "" + } + }) + + "`$env:INSTALLER_SCRIPT = $(ConvertTo-Injection (Resolve-Path $env:INSTALLER_SCRIPT));" + + "`$env:CONFIG_MODULE = $(ConvertTo-Injection ($env:CONFIG_MODULE));" + + "& `$env:INSTALLER_SCRIPT;"; + } + <# .SYNOPSIS Registers a task to run the setup once after the next reboot. @@ -65,20 +91,7 @@ $null = New-Module { $key = Get-RunOnceKey; } - Set-ItemProperty -Path $key.PSPath -Name $runOnceName -Type "ExpandString" -Value ( - "pwsh -Command " + - (& { - if ($env:PWSH_PATH) { - "`$env:PWSH_PATH = $(ConvertTo-Injection $env:PWSH_PATH);" - } else { - "" - } - }) + - "`$env:INSTALLER_SCRIPT = $(ConvertTo-Injection (Resolve-Path $env:INSTALLER_SCRIPT));" + - "`$env:CONFIG_MODULE = $(ConvertTo-Injection $env:CONFIG_MODULE);" + - "& `$env:INSTALLER_SCRIPT;" - ); - + Set-ItemProperty -Path $key.PSPath -Name $runOnceName -Type "ExpandString" -Value (Get-StartupScript); $key.Handle.Close(); }