$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)"; $partitionCreations = $diskConfig.SelectSingleNode("./ua:CreatePartitions", $namespace); $winPartition = ($partitionCreations.SelectNodes("./ua:CreatePartition", $namespace) | Select-Object -Last)[0]; $newPartition = $winPartition.CloneNode($true); $offset = 0; for ($i = 0; $i -lt $partitionCreations.ChildNodes.Count; $i++) { $partition = $partitionCreations.ChildNodes[$i]; $order = [int]$partition.SelectSingleNode("./ua:Order", $namespace).InnerText; $offset += [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) - $offset)"; $winPartition.RemoveChild($winPartition.SelectSingleNode("./Extend")); $winPartition.AppendChild($size); $newPartition.SelectSingleNode("./ua:Order", $namespace).InnerText = "$newIndex"; $null = $partitionCreations.AppendChild($newPartition); $partitionModifications = $diskConfig.SelectSingleNode("./ua:ModifyPartitions", $namespace); $newModification = $partitionModifications.SelectNodes("./ua:ModifyPartition", $namespace)[2].CloneNode($true); $newModification.SelectSingleNode("./ua:Order", $namespace).InnerText = "$newIndex"; $newModification.SelectSingleNode("./ua:PartitionID", $namespace).InnerText = "$newIndex"; for ($i = 0; $i -lt $partitionModifications.ChildNodes.Count; $i++) { $partition = $partitionModifications.ChildNodes[$i]; $partitionID = [int]$partition.SelectSingleNode("./ua:PartitionID", $namespace).InnerText; if ($partitionID -ge $newIndex) { $partition.SelectSingleNode("./ua:PartitionID", $namespace).InnerText = "$($partitionID + 1)"; $partition.SelectSingleNode("./ua:Order", $namespace).InnerText = "$($partitionID + 1)"; } } $null = $partitionModifications.AppendChild($newModification); } . "$PSScriptRoot/../../../scripts/Windows/OS/Setup.ps1";