Add a function for queueing startup commands

This commit is contained in:
Manuel Thalmann 2024-08-15 18:34:48 +02:00
parent 38c37c3564
commit 16560270a7

View file

@ -186,6 +186,20 @@ function Start-Setup {
Move-PartitionRange -Disk $Disk -1 -1 ($To + 1) Move-PartitionRange -Disk $Disk -1 -1 ($To + 1)
} }
function Add-StartupCommand {
param(
[string] $Script,
[string] $Description
)
$installationCommand = $oobeSettings.SelectSingleNode("./ua:FirstLogonCommands/ua:SynchronousCommand[last()]", $namespace);
$newCommand = $installationCommand.ParentNode.AppendChild($installationCommand.CloneNode($true));
$newCommand.SelectSingleNode("./ua:CommandLine", $namespace).InnerText = $Script;
$orderElement = $newCommand.SelectSingleNode("./ua:Order", $namespace);
$orderElement.InnerText = ([int]($orderElement.InnerText) + 1);
$newCommand.SelectSingleNode("./ua:Description", $namespace).InnerText = $Description;
}
# Collect necessary variables # Collect necessary variables
$winpePass = Get-PassSettings "windowsPE"; $winpePass = Get-PassSettings "windowsPE";
$setupConfig = Get-Component $winpePass "Microsoft-Windows-Setup"; $setupConfig = Get-Component $winpePass "Microsoft-Windows-Setup";
@ -213,19 +227,14 @@ function Start-Setup {
$oobeSettings.SelectSingleNode($xpath, $namespace).InnerText = $valhallaConfig.setupUser; $oobeSettings.SelectSingleNode($xpath, $namespace).InnerText = $valhallaConfig.setupUser;
} }
$installationCommand = $oobeSettings.SelectSingleNode("./ua:FirstLogonCommands/ua:SynchronousCommand[last()]", $namespace); Add-StartupCommand `
$newCommand = $installationCommand.ParentNode.AppendChild($installationCommand.CloneNode($true)); -Script (
"powershell -Command " +
$newCommand.SelectSingleNode("./ua:CommandLine", $namespace).InnerText = ` "`$env:PWSH_PATH = $(Get-PathInjection $env:PWSH_PATH);" +
"powershell -Command " + ` "`$env:INSTALLER_SCRIPT = $(Get-ScriptPathInjection $env:SETUP_SCRIPT_NAME);" +
"`$env:PWSH_PATH = $(Get-PathInjection $env:PWSH_PATH);" + ` "`$env:CONFIG_MODULE = $(Get-ScriptPathInjection $env:CONFIG_MODULE);" +
"`$env:INSTALLER_SCRIPT = $(Get-ScriptPathInjection $env:SETUP_SCRIPT_NAME);" + ` "& (Join-Path `$env:PWSH_PATH pwsh) `$env:INSTALLER_SCRIPT;") `
"`$env:CONFIG_MODULE = $(Get-ScriptPathInjection $env:CONFIG_MODULE);" + ` -Description "Install PowerShell Core and git and run setup script";
"& (Join-Path `$env:PWSH_PATH pwsh) `$env:INSTALLER_SCRIPT;";
$orderElement = $newCommand.SelectSingleNode("./ua:Order", $namespace);
$orderElement.InnerText = ([int]($orderElement.InnerText) + 1);
$newCommand.SelectSingleNode("./ua:Description", $namespace).InnerText = "Install PowerShell Core and git and run setup script";
if ($valhallaConfig.dualboot.enable) { if ($valhallaConfig.dualboot.enable) {
$diskSize = [long](ConvertFrom-Csv (wmic diskdrive where "Index=$(Get-InstallDisk)" get Size | ForEach-Object { "$_".Trim(); })).Size; $diskSize = [long](ConvertFrom-Csv (wmic diskdrive where "Index=$(Get-InstallDisk)" get Size | ForEach-Object { "$_".Trim(); })).Size;