PortValhalla/scripts/Windows/OS/Setup.ps1

45 lines
1.8 KiB
PowerShell
Raw Normal View History

2023-07-12 20:37:31 +00:00
#!/bin/pwsh
2023-06-21 20:10:19 +00:00
$null = $env:WIN_COMPUTER_NAME;
$null = $env:SETUP_SCRIPT_NAME;
2023-06-22 13:43:16 +00:00
# Find `winiso` installation medium
$drives = & wmic volume get "DriveLetter,Label";
$drive = $($($drives | Select-String -Pattern "winiso") -split "\s+")[0];
[xml]$unattendedConfig = [xml]::new();
$unattendedConfig.PreserveWhitespace = $true;
$readerSettings = [System.Xml.XmlReaderSettings]::new();
$readerSettings.IgnoreComments = $true;
$reader = [System.Xml.XmlReader]::Create("$drive\Autounattend.template.xml", $readerSettings);
$unattendedConfig.Load($reader);
2023-06-22 14:05:10 +00:00
$namespace = New-Object -TypeName "Xml.XmlNamespaceManager" -ArgumentList $unattendedConfig.NameTable;
$namespace.AddNamespace("ua", $unattendedConfig.DocumentElement.NamespaceURI);
2023-06-21 20:10:19 +00:00
function Get-PassSettings {
[OutputType([xml])]
param(
[string] $passName
)
2023-06-22 14:05:10 +00:00
return $unattendedConfig.SelectSingleNode("/ua:unattend/ua:settings[@pass='$passName']", $namespace);
2023-06-21 20:10:19 +00:00
}
# Adjust unattended settings
$specializeSettings = Get-PassSettings "specialize";
2023-06-22 14:11:32 +00:00
$specializeSettings.SelectSingleNode("./ua:component[@name='Microsoft-Windows-Shell-Setup']/ua:ComputerName", $namespace).InnerText = "$env:WIN_COMPUTER_NAME";
2023-06-21 20:10:19 +00:00
$oobeSystemSettings = Get-PassSettings "oobeSystem";
2023-06-25 11:43:46 +00:00
$oobeSystemSettings.SelectSingleNode("./ua:component/ua:FirstLogonCommands/ua:SynchronousCommand[last()]/ua:CommandLine", $namespace).InnerText += "`npwsh '$env:SETUP_SCRIPT_NAME';";
2023-06-21 20:10:19 +00:00
if ($Global:SetupConfigPostprocessor) {
2023-07-03 10:44:36 +00:00
$Global:SetupConfigPostprocessor.Invoke($unattendedConfig, $namespace);
}
2023-06-22 14:50:40 +00:00
$unattendedConfig.PreserveWhitespace = $true;
2023-06-22 14:17:02 +00:00
$unattendedConfig.Save("$drive\Autounattend.xml");
2023-06-21 20:10:19 +00:00
Write-Warning "Attention: This program will completely wipe your current disk #1 and install Windows on it. Are you sure you want to do this?"
Read-Host -Prompt "Hit enter to continue or CTRL+C to abort"
& "$drive\setup.exe";