Drop the use of modules
This commit is contained in:
parent
c29a08919e
commit
ba1d13d7ee
1 changed files with 96 additions and 98 deletions
|
@ -8,122 +8,120 @@ function Initialize-SetupConfig() {
|
||||||
[System.Xml.XmlNamespaceManager] $namespace
|
[System.Xml.XmlNamespaceManager] $namespace
|
||||||
);
|
);
|
||||||
|
|
||||||
$null = New-Module {
|
$setupComponent = $config.SelectSingleNode(
|
||||||
$setupComponent = $config.SelectSingleNode(
|
"/ua:unattend/ua:settings[@pass='windowsPE']/ua:component[@name='Microsoft-Windows-Setup']",
|
||||||
"/ua:unattend/ua:settings[@pass='windowsPE']/ua:component[@name='Microsoft-Windows-Setup']",
|
$namespace);
|
||||||
$namespace);
|
|
||||||
|
|
||||||
$diskConfig = $setupComponent.SelectSingleNode("./ua:DiskConfiguration/ua:Disk", $namespace);
|
$diskConfig = $setupComponent.SelectSingleNode("./ua:DiskConfiguration/ua:Disk", $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);
|
||||||
|
|
||||||
$partitionModificationContainer = $diskConfig.SelectSingleNode("./ua:ModifyPartitions", $namespace);
|
$partitionModificationContainer = $diskConfig.SelectSingleNode("./ua:ModifyPartitions", $namespace);
|
||||||
$partitionModifications = $partitionModificationContainer.SelectNodes("./ua:ModifyPartition", $namespace);
|
$partitionModifications = $partitionModificationContainer.SelectNodes("./ua:ModifyPartition", $namespace);
|
||||||
|
|
||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Gets the XML element describing the installation partition ID.
|
Gets the XML element describing the installation partition ID.
|
||||||
#>
|
#>
|
||||||
function Get-InstallationPartition {
|
function Get-InstallationPartition {
|
||||||
$setupComponent.SelectSingleNode("./ua:ImageInstall/ua:OSImage/ua:InstallTo/ua:PartitionID", $namespace)
|
$setupComponent.SelectSingleNode("./ua:ImageInstall/ua:OSImage/ua:InstallTo/ua:PartitionID", $namespace)
|
||||||
|
}
|
||||||
|
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Increases the ID of all partitions in the specified range by 1.
|
||||||
|
#>
|
||||||
|
function Move-PartitionRange {
|
||||||
|
param (
|
||||||
|
[int]$From = 0,
|
||||||
|
[System.Nullable[int]]$To = $null,
|
||||||
|
[int]$By = 1
|
||||||
|
)
|
||||||
|
|
||||||
|
# Update installation partition ID if necessary
|
||||||
|
$installationPartition = Get-InstallationPartition;
|
||||||
|
$installPartitionID = [int]$installationPartition.InnerText;
|
||||||
|
|
||||||
|
if (($installPartitionID -ge $From) -and (($null -eq $To) -or ($installPartitionID -le $To))) {
|
||||||
|
$installationPartition.InnerText = "$($installPartitionID + $By)";
|
||||||
}
|
}
|
||||||
|
|
||||||
<#
|
# Update IDs of all partition creations
|
||||||
.SYNOPSIS
|
foreach ($partition in $partitionCreations) {
|
||||||
Increases the ID of all partitions in the specified range by 1.
|
$orderNode = $partition.SelectSingleNode("./ua:Order", $namespace);
|
||||||
#>
|
$order = [int]$orderNode.InnerText;
|
||||||
function Move-PartitionRange {
|
$newOrder = $order;
|
||||||
param (
|
|
||||||
[int]$From = 0,
|
|
||||||
[System.Nullable[int]]$To = $null,
|
|
||||||
[int]$By = 1
|
|
||||||
)
|
|
||||||
|
|
||||||
# Update installation partition ID if necessary
|
if (($newOrder -ge $From) -and (($null -eq $To) -or ($newOrder -le $To))) {
|
||||||
$installationPartition = Get-InstallationPartition;
|
$newOrder += $By;
|
||||||
$installPartitionID = [int]$installationPartition.InnerText;
|
|
||||||
|
|
||||||
if (($installPartitionID -ge $From) -and (($null -eq $To) -or ($installPartitionID -le $To))) {
|
|
||||||
$installationPartition.InnerText = "$($installPartitionID + $By)";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Update IDs of all partition creations
|
if ($order -ne $newOrder) {
|
||||||
foreach ($partition in $partitionCreations) {
|
$orderNode.InnerText = "$newOrder";
|
||||||
$orderNode = $partition.SelectSingleNode("./ua:Order", $namespace);
|
|
||||||
$order = [int]$orderNode.InnerText;
|
|
||||||
$newOrder = $order;
|
|
||||||
|
|
||||||
if (($newOrder -ge $From) -and (($null -eq $To) -or ($newOrder -le $To))) {
|
|
||||||
$newOrder += $By;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($order -ne $newOrder) {
|
|
||||||
$orderNode.InnerText = "$newOrder";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Update IDs of all partition modifications
|
|
||||||
foreach ($partition in $partitionModifications) {
|
|
||||||
$partitionNode = $partition.SelectSingleNode("./ua:PartitionID", $namespace);
|
|
||||||
$partitionID = [int]$partitionNode.InnerText;
|
|
||||||
$newID = $partitionID;
|
|
||||||
|
|
||||||
if (($newID -ge $From) -and (($null -eq $To) -or ($newID -le $To))) {
|
|
||||||
$newID += $By;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($partitionID -ne $newID) {
|
|
||||||
$partitionNode.InnerText = "$newID";
|
|
||||||
$partition.SelectSingleNode("./ua:Order", $namespace).InnerText = "$newID";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Add-Partition {
|
# Update IDs of all partition modifications
|
||||||
param (
|
foreach ($partition in $partitionModifications) {
|
||||||
[int]$Index,
|
$partitionNode = $partition.SelectSingleNode("./ua:PartitionID", $namespace);
|
||||||
[int]$Size,
|
$partitionID = [int]$partitionNode.InnerText;
|
||||||
[string]$Type = "Primary"
|
$newID = $partitionID;
|
||||||
)
|
|
||||||
|
|
||||||
Move-PartitionRange -From $Index -By 1;
|
if (($newID -ge $From) -and (($null -eq $To) -or ($newID -le $To))) {
|
||||||
|
$newID += $By;
|
||||||
$newPartition = $partitionCreations[0].CloneNode($true);
|
|
||||||
$newPartition.SelectSingleNode("./ua:Order", $namespace).InnerText = "$Index";
|
|
||||||
$newPartition.SelectSingleNode("./ua:Type", $namespace).InnerText = "$Type";
|
|
||||||
$newPartition.SelectSingleNode("./ua:Size", $namespace).InnerText = "$Size";
|
|
||||||
$null = $partitionCreationContainer.AppendChild($newPartition);
|
|
||||||
|
|
||||||
$newModification = $partitionModifications[2].CloneNode($true);
|
|
||||||
$newModification.SelectSingleNode("./ua:Order", $namespace).InnerText = "$Index";
|
|
||||||
$newModification.SelectSingleNode("./ua:PartitionID", $namespace).InnerText = "$Index";
|
|
||||||
$null = $partitionModificationContainer.AppendChild($newModification);
|
|
||||||
}
|
|
||||||
|
|
||||||
<#
|
|
||||||
.SYNOPSIS
|
|
||||||
Relocates the partition with the specified `$From` ID to the specified `$To` ID.
|
|
||||||
#>
|
|
||||||
function Invoke-PartitionRelocation {
|
|
||||||
param (
|
|
||||||
[int]$From,
|
|
||||||
[int]$To
|
|
||||||
)
|
|
||||||
|
|
||||||
Move-PartitionRange $From $From (-1 * ($From + 1))
|
|
||||||
|
|
||||||
if ($From -gt $To) {
|
|
||||||
Move-PartitionRange $To ($From - 1);
|
|
||||||
}
|
|
||||||
elseif ($From -lt $To) {
|
|
||||||
Move-PartitionRange ($From + 1) $To -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Move-PartitionRange -1 -1 ($To + 1)
|
if ($partitionID -ne $newID) {
|
||||||
|
$partitionNode.InnerText = "$newID";
|
||||||
|
$partition.SelectSingleNode("./ua:Order", $namespace).InnerText = "$newID";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Add-Partition {
|
||||||
|
param (
|
||||||
|
[int]$Index,
|
||||||
|
[int]$Size,
|
||||||
|
[string]$Type = "Primary"
|
||||||
|
)
|
||||||
|
|
||||||
|
Move-PartitionRange -From $Index -By 1;
|
||||||
|
|
||||||
|
$newPartition = $partitionCreations[0].CloneNode($true);
|
||||||
|
$newPartition.SelectSingleNode("./ua:Order", $namespace).InnerText = "$Index";
|
||||||
|
$newPartition.SelectSingleNode("./ua:Type", $namespace).InnerText = "$Type";
|
||||||
|
$newPartition.SelectSingleNode("./ua:Size", $namespace).InnerText = "$Size";
|
||||||
|
$null = $partitionCreationContainer.AppendChild($newPartition);
|
||||||
|
|
||||||
|
$newModification = $partitionModifications[2].CloneNode($true);
|
||||||
|
$newModification.SelectSingleNode("./ua:Order", $namespace).InnerText = "$Index";
|
||||||
|
$newModification.SelectSingleNode("./ua:PartitionID", $namespace).InnerText = "$Index";
|
||||||
|
$null = $partitionModificationContainer.AppendChild($newModification);
|
||||||
|
}
|
||||||
|
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Relocates the partition with the specified `$From` ID to the specified `$To` ID.
|
||||||
|
#>
|
||||||
|
function Invoke-PartitionRelocation {
|
||||||
|
param (
|
||||||
|
[int]$From,
|
||||||
|
[int]$To
|
||||||
|
)
|
||||||
|
|
||||||
|
Move-PartitionRange $From $From (-1 * ($From + 1))
|
||||||
|
|
||||||
|
if ($From -gt $To) {
|
||||||
|
Move-PartitionRange $To ($From - 1);
|
||||||
|
}
|
||||||
|
elseif ($From -lt $To) {
|
||||||
|
Move-PartitionRange ($From + 1) $To -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Move-PartitionRange -1 -1 ($To + 1)
|
||||||
|
}
|
||||||
|
|
||||||
# Resize EFI partition to 1GB
|
# Resize EFI partition to 1GB
|
||||||
$partitionCreations[1].SelectSingleNode("./ua:Size", $namespace).InnerText = "$(1024)";
|
$partitionCreations[1].SelectSingleNode("./ua:Size", $namespace).InnerText = "$(1024)";
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue