diff --git a/profiles/DerGeret/Windows/Setup.ps1 b/profiles/DerGeret/Windows/Setup.ps1 index 2bc13dc5..b6e261c1 100644 --- a/profiles/DerGeret/Windows/Setup.ps1 +++ b/profiles/DerGeret/Windows/Setup.ps1 @@ -1,3 +1,41 @@ $env:WIN_COMPUTER_NAME = "DerGeret"; $env:SETUP_SCRIPT_NAME = [System.IO.Path]::GetRelativePath("$PSScriptRoot/../../..", "$PSScriptRoot/Restore.ps1"); . "$PSScriptRoot/../../../scripts/Windows/OS/Setup.ps1"; + +$Global:SetupConfigPostprocessor = { + param([xml] $config, [System.Xml.XmlNamespaceManager] $namespace) + + $diskConfig = $config.SelectSingleNode( + "/ua:unattend/ua:settings[@pass='windowsPE']/ua:component[@name='Microsoft-Windows-Setup']/ua:DiskConfiguration/ua:Disk", + $namespace); + + $newIndex = 4; + $partitionCreations = $diskConfig.SelectSingleNode("./ua:CreatePartitions"); + $newPartition = $partitionCreations.FirstChild.CloneNode($true); + $newPartition.SelectSingleNode("./ua:Order").InnerText = "$newIndex"; + $newPartition.SelectSingleNode("./ua:Size").InnerText = "65536"; # For testing purposes + + for ($i = 0; $i -lt $partitionCreations.ChildNodes.Count; $i++) { + $partition = $partitionCreations.ChildNodes[$i]; + $order = [int]$partition.SelectSingleNode("./ua:Order").InnerText; + + if ($order -ge $newIndex) { + $partition.SelectSingleNode("./ua:Order").InnerText = "$($order + 1)"; + } + } + + $partitionModifications = $diskConfig.SelectSingleNode("./ua:ModifyPartitions"); + $newModification = $diskConfig.ChildNodes[2].CloneNode($true); + $newModification.SelectSingleNode("./ua:Order").InnerText = "$newIndex"; + $newModification.SelectSingleNode("./ua:PartitionID").InnerText = "$newIndex"; + + for ($i = 0; $i -lt $partitionModifications.ChildNodes.Count; $i++) { + $partition = $partitionModifications.ChildNodes[$i]; + $partitionID = [int]$partition.SelectSingleNode("./ua:PartitionID").InnerText; + + if ($partitionID -ge $newIndex) { + $partition.SelectSingleNode("./ua:PartitionID").InnerText = "$($partitionID + 1)"; + $partition.SelectSingleNode("./ua:Order").InnerText = "$($partitionID + 1)"; + } + } +} diff --git a/scripts/Windows/OS/Setup.ps1 b/scripts/Windows/OS/Setup.ps1 index c6077654..f0348e53 100644 --- a/scripts/Windows/OS/Setup.ps1 +++ b/scripts/Windows/OS/Setup.ps1 @@ -31,6 +31,10 @@ $specializeSettings.SelectSingleNode("./ua:component[@name='Microsoft-Windows-Sh $oobeSystemSettings = Get-PassSettings "oobeSystem"; $oobeSystemSettings.SelectSingleNode("./ua:component/ua:FirstLogonCommands/ua:SynchronousCommand[last()]/ua:CommandLine", $namespace).InnerText += "`npwsh '$env:SETUP_SCRIPT_NAME';"; +if ($Global:SetupConfigPostprocessor) { + $Global:SetupConfigPostprocessorpartitionCreations.Invoke($unattendedConfig, $namespace); +} + $unattendedConfig.PreserveWhitespace = $true; $unattendedConfig.Save("$drive\Autounattend.xml");