Improve partition script

This commit is contained in:
Manuel Thalmann 2024-03-23 14:00:42 +01:00
parent b7f7a53b67
commit cda0a62bf0

View file

@ -9,6 +9,14 @@ function Initialize-SetupConfig() {
); );
New-Module { New-Module {
<#
.SYNOPSIS
Gets the XML element describing the installation partition ID.
#>
Get-InstallationPartition {
$setupComponent.SelectSingleNode("./ua:ImageInstall/ua:OSImage/ua:InstallTo/ua:PartitionID", $namespace)
}
<# <#
.SYNOPSIS .SYNOPSIS
Increases the ID of all partitions in the specified range by 1. Increases the ID of all partitions in the specified range by 1.
@ -20,12 +28,15 @@ function Initialize-SetupConfig() {
[int]$By = 1 [int]$By = 1
) )
# Update installation partition ID if necessary
$installationPartition = Get-InstallationPartition;
$installPartitionID = [int]$installationPartition.InnerText; $installPartitionID = [int]$installationPartition.InnerText;
if (($installPartitionID -ge $From) -and (($null -eq $To) -or ($installPartitionID -lt $To))) { if (($installPartitionID -ge $From) -and (($null -eq $To) -or ($installPartitionID -lt $To))) {
$installationPartition.InnerText = "$($installPartitionID + $By)"; $installationPartition.InnerText = "$($installPartitionID + $By)";
} }
# Update IDs of all partition creations
foreach ($partition in $partitionCreations) { foreach ($partition in $partitionCreations) {
$orderNode = $partition.SelectSingleNode("./ua:Order", $namespace); $orderNode = $partition.SelectSingleNode("./ua:Order", $namespace);
$order = [int]$orderNode.InnerText; $order = [int]$orderNode.InnerText;
@ -40,6 +51,7 @@ function Initialize-SetupConfig() {
} }
} }
# Update IDs of all partition modifications
foreach ($partition in $partitionModifications) { foreach ($partition in $partitionModifications) {
$partitionNode = $partition.SelectSingleNode("./ua:PartitionID", $namespace); $partitionNode = $partition.SelectSingleNode("./ua:PartitionID", $namespace);
$partitionID = [int]$partitionNode.InnerText; $partitionID = [int]$partitionNode.InnerText;
@ -105,7 +117,6 @@ function Initialize-SetupConfig() {
$namespace); $namespace);
$diskConfig = $setupComponent.SelectSingleNode("./ua:DiskConfiguration/ua:Disk", $namespace); $diskConfig = $setupComponent.SelectSingleNode("./ua:DiskConfiguration/ua:Disk", $namespace);
$installationPartition = $setupComponent.SelectSingleNode("./ua:ImageInstall/ua:OSImage/ua:InstallTo/ua:PartitionID", $namespace);
$partitionCreationContainer = $diskConfig.SelectSingleNode("./ua:CreatePartitions", $namespace); $partitionCreationContainer = $diskConfig.SelectSingleNode("./ua:CreatePartitions", $namespace);
$partitionCreations = $partitionCreationContainer.SelectNodes("./ua:CreatePartition", $namespace); $partitionCreations = $partitionCreationContainer.SelectNodes("./ua:CreatePartition", $namespace);