Refactor the format of the Autounattend.xml file

This commit is contained in:
Manuel Thalmann 2023-06-25 11:49:50 +02:00
parent 0ba664eb51
commit ebcac5536d

View file

@ -4,7 +4,14 @@ $null = $env:SETUP_SCRIPT_NAME;
# Find `winiso` installation medium # Find `winiso` installation medium
$drives = & wmic volume get "DriveLetter,Label"; $drives = & wmic volume get "DriveLetter,Label";
$drive = $($($drives | Select-String -Pattern "winiso") -split "\s+")[0]; $drive = $($($drives | Select-String -Pattern "winiso") -split "\s+")[0];
[xml]$unattendedConfig = $(Get-Content "$drive\Autounattend.template.xml"); [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);
$namespace = New-Object -TypeName "Xml.XmlNamespaceManager" -ArgumentList $unattendedConfig.NameTable; $namespace = New-Object -TypeName "Xml.XmlNamespaceManager" -ArgumentList $unattendedConfig.NameTable;
$namespace.AddNamespace("ua", $unattendedConfig.DocumentElement.NamespaceURI); $namespace.AddNamespace("ua", $unattendedConfig.DocumentElement.NamespaceURI);