$env:WIN_COMPUTER_NAME = "DerGeret"; $env:SETUP_SCRIPT_NAME = [System.IO.Path]::GetRelativePath("$PSScriptRoot/../../..", "$PSScriptRoot/Restore.ps1"); $Global:SetupConfigPostprocessor = { param([xml] $config, [System.Xml.XmlNamespaceManager] $namespace) $setupComponent = $config.SelectSingleNode( "/ua:unattend/ua:settings[@pass='windowsPE']/ua:component[@name='Microsoft-Windows-Setup']", $namespace); $diskConfig = $setupComponent.SelectSingleNode("./ua:DiskConfiguration/ua:Disk", $namespace); $installationPartition = $setupComponent.SelectSingleNode("./ua:ImageInstall/ua:OSImage/ua:InstallTo/ua:PartitionID", $namespace); $newIndex = 2; $installationPartition.InnerText = "$($newIndex + 1)"; $partitionCreationContainer = $diskConfig.SelectSingleNode("./ua:CreatePartitions", $namespace); $partitionCreations = $partitionCreationContainer.SelectNodes("./ua:CreatePartition", $namespace); $winPartition = ($partitionCreations | Select-Object -Last 1); $newPartition = $winPartition.CloneNode($true); $garbage = 0; foreach ($partition in $partitionCreations) { $order = [int]$partition.SelectSingleNode("./ua:Order", $namespace).InnerText; $garbage += [int]$partition.SelectSingleNode("./ua:Size", $namespace).InnerText; $newOrder = $order; if ($order -eq 2) { $newOrder--; } else { if ($order -ge $newIndex) { $newOrder++; } if ($order -lt 2) { $newOrder++; } } if ($order -ne $newOrder) { $partition.SelectSingleNode("./ua:Order", $namespace).InnerText = "$newOrder"; } } # Add space before Windows installation... wha-!? For Linux, ofc! I use Arch Linux, btw. $size = $winPartition.OwnerDocument.CreateElement("Size"); $size.InnerText = "$((1 * 1024 * 1024) - $garbage)"; $winPartition.RemoveChild($winPartition.SelectSingleNode("./ua:Extend", $namespace)); $winPartition.AppendChild($size); $newPartition.SelectSingleNode("./ua:Order", $namespace).InnerText = "$newIndex"; $null = $partitionCreationContainer.AppendChild($newPartition); $partitionModificationContainer = $diskConfig.SelectSingleNode("./ua:ModifyPartitions", $namespace); $partitionModifications = $partitionModificationContainer.SelectNodes("./ua:ModifyPartition", $namespace); $newModification = $partitionModifications[1].CloneNode($true); $newModification.SelectSingleNode("./ua:Order", $namespace).InnerText = "$newIndex"; $newModification.SelectSingleNode("./ua:PartitionID", $namespace).InnerText = "$newIndex"; foreach ($partition in $partitionModifications) { $partitionID = [int]$partition.SelectSingleNode("./ua:PartitionID", $namespace).InnerText; $newID = $partitionID; if ($partitionID -eq 2) { $newID--; } else { if ($partitionID -ge $newIndex) { $newID++; } if ($partitionID -lt 2) { $newID++; } } if ($partitionID -ne $newID) { $partition.SelectSingleNode("./ua:PartitionID", $namespace).InnerText = "$newID"; $partition.SelectSingleNode("./ua:Order", $namespace).InnerText = "$newID"; } } $null = $partitionModificationContainer.AppendChild($newModification); } . "$PSScriptRoot/../../../scripts/Windows/OS/Setup.ps1";