2021-01-23 14:59:06 +00:00
|
|
|
#Requires -Modules 'powershell-yaml'
|
|
|
|
[CmdletBinding()]
|
|
|
|
Param(
|
|
|
|
[Parameter(Mandatory)]
|
|
|
|
[ValidateScript({
|
|
|
|
If (Test-Path($_)) {
|
|
|
|
$True
|
|
|
|
} Else {
|
|
|
|
Throw "'$_' is not a valid filename (within working directory '$PWD'), or access denied; aborting."
|
|
|
|
}
|
|
|
|
})]
|
|
|
|
[string]$OVFFile,
|
|
|
|
[hashtable]$Parameter
|
|
|
|
)
|
|
|
|
|
|
|
|
$GetContentSplat = @{
|
|
|
|
Path = "$($PSScriptRoot)\$($MyInvocation.MyCommand)".Replace('.ps1', ".yml")
|
|
|
|
Raw = $True
|
|
|
|
}
|
|
|
|
$RawContent = Get-Content @GetContentSplat
|
|
|
|
$ConvertFromYamlSplat = @{
|
|
|
|
Yaml = $RawContent
|
|
|
|
AllDocuments = $True
|
|
|
|
}
|
|
|
|
$YamlDocuments = ConvertFrom-Yaml @ConvertFromYamlSplat
|
|
|
|
|
|
|
|
# Check if the respective .yml file declared substitutions which need to be parsed
|
|
|
|
If (($YamlDocuments.Count -gt 1) -and $YamlDocuments[-1].Variables) {
|
|
|
|
ForEach ($Pattern in $YamlDocuments[-1].Variables) {
|
|
|
|
$RawContent = $RawContent -replace "\{\{ ($($Pattern.Name)) \}\}", [string](Invoke-Expression -Command $Pattern.Expression)
|
|
|
|
}
|
|
|
|
# Perform conversion to Yaml again, now with parsed file contents
|
|
|
|
$ConvertFromYamlSplat = @{
|
|
|
|
Yaml = $RawContent
|
|
|
|
AllDocuments = $True
|
|
|
|
}
|
|
|
|
$YamlDocuments = ConvertFrom-Yaml @ConvertFromYamlSplat
|
|
|
|
$OVFConfig = $YamlDocuments[0..($YamlDocuments.Count - 2)]
|
|
|
|
}
|
|
|
|
Else {
|
|
|
|
$OVFConfig = $YamlDocuments
|
|
|
|
}
|
|
|
|
|
|
|
|
$SourceFile = Get-Item -Path $OVFFile
|
|
|
|
$GetContentSplat = @{
|
|
|
|
Path = $SourceFile.FullName
|
|
|
|
}
|
|
|
|
$XML = [xml](Get-Content @GetContentSplat)
|
|
|
|
$NS = [System.Xml.XmlNamespaceManager]$XML.NameTable
|
2021-05-10 13:17:29 +00:00
|
|
|
[void]$NS.AddNamespace('ns', $XML.DocumentElement.xmlns)
|
|
|
|
[void]$NS.AddNamespace('ovf', $XML.DocumentElement.ovf)
|
2021-05-11 13:13:14 +00:00
|
|
|
[void]$NS.AddNamespace('rasd', $XML.DocumentElement.rasd)
|
2021-05-12 13:25:29 +00:00
|
|
|
[void]$NS.AddNamespace('vmw', $XML.DocumentElement.vmw)
|
2021-05-10 13:17:29 +00:00
|
|
|
|
2021-05-12 13:25:29 +00:00
|
|
|
# Create copy of existing 'Item/ResourceType'=17 (=Hard disk) node
|
2021-05-11 13:13:14 +00:00
|
|
|
$XMLDiskTemplate = $XML.SelectSingleNode("//ns:VirtualHardwareSection/ns:Item/rasd:ResourceType[.='17']", $NS).ParentNode.CloneNode($True)
|
2021-05-10 21:13:04 +00:00
|
|
|
|
2021-05-11 13:13:14 +00:00
|
|
|
ForEach ($Disk in $OVFConfig.DynamicDisks) {
|
2021-05-12 13:25:29 +00:00
|
|
|
# Determine next free available 'diskId'
|
2021-05-10 14:27:49 +00:00
|
|
|
$XMLDisks = $XML.SelectNodes("//ns:DiskSection/ns:Disk[contains(@ovf:diskId,'vmdisk')]", $NS)
|
2021-05-12 13:25:29 +00:00
|
|
|
$DiskId = 1
|
2021-05-10 13:17:29 +00:00
|
|
|
While ($XMLDisks.DiskId -contains "vmdisk$($DiskId)") {
|
|
|
|
$DiskId++
|
|
|
|
}
|
|
|
|
|
2021-05-12 13:25:29 +00:00
|
|
|
# Add new 'Disk' node (under 'DiskSection')
|
2021-05-10 13:17:29 +00:00
|
|
|
$XMLDisk = $XML.CreateElement('Disk', $XML.DocumentElement.xmlns)
|
2021-05-12 13:25:29 +00:00
|
|
|
$PowersMap = @{
|
|
|
|
KB = 10
|
|
|
|
MB = 20
|
|
|
|
GB = 30
|
|
|
|
TB = 40
|
|
|
|
PB = 50
|
2021-05-10 13:17:29 +00:00
|
|
|
}
|
2021-05-12 13:25:29 +00:00
|
|
|
If ($PowersMap.Keys -notcontains $Disk.UnitSize) {
|
|
|
|
# Invalid UnitSize; skipping adding new disk
|
|
|
|
Continue
|
|
|
|
}
|
|
|
|
|
|
|
|
[void]$XMLDisk.SetAttribute('capacityAllocationUnits', $NS.LookupNamespace('ovf'), "byte * 2^$($PowersMap[$Disk.UnitSize])")
|
2021-05-12 10:54:11 +00:00
|
|
|
[void]$XMLDisk.SetAttribute('format', $NS.LookupNamespace('ovf'), 'http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized')
|
|
|
|
[void]$XMLDisk.SetAttribute('diskId', $NS.LookupNamespace('ovf'), "vmdisk$($DiskId)")
|
|
|
|
[void]$XMLDisk.SetAttribute('capacity', $NS.LookupNamespace('ovf'), '${{vmconfig.disksize.{0}}}' -f $DiskId)
|
|
|
|
[void]$XMLDisk.SetAttribute('populatedSize', $NS.LookupNamespace('ovf'), 0)
|
2021-05-10 21:13:04 +00:00
|
|
|
[void]$XML.SelectSingleNode('//ns:DiskSection', $NS).AppendChild($XMLDisk)
|
|
|
|
|
2021-05-12 13:25:29 +00:00
|
|
|
# Add new 'Item/ResourceType' node (under 'VirtualHardwareSection')
|
2021-05-11 13:13:14 +00:00
|
|
|
$XMLDiskItem = $XMLDiskTemplate.CloneNode($True)
|
|
|
|
$XMLDiskItem.SelectSingleNode('rasd:AddressOnParent', $NS).InnerText = ($DiskId - 1)
|
|
|
|
$XMLDiskItem.SelectSingleNode('rasd:ElementName', $NS).InnerText = "Hard Disk $($DiskId)"
|
|
|
|
$XMLDiskItem.SelectSingleNode('rasd:HostResource', $NS).InnerText = "ovf:/disk/vmdisk$($DiskId)"
|
2021-05-19 08:03:52 +00:00
|
|
|
# Determine next free available and highest 'InstanceID'
|
|
|
|
$InstanceIDs = $XML.SelectNodes('//ns:VirtualHardwareSection/ns:Item/rasd:InstanceID', $NS).InnerText
|
2021-05-11 13:13:14 +00:00
|
|
|
$InstanceID = 1
|
2021-05-19 08:03:52 +00:00
|
|
|
While ($InstanceIDs -contains $InstanceID) {
|
2021-05-11 13:13:14 +00:00
|
|
|
$InstanceID++
|
|
|
|
}
|
2021-05-19 08:03:52 +00:00
|
|
|
$HighestInstanceID = ($InstanceIDs | Measure-Object -Maximum).Maximum
|
2021-05-11 13:13:14 +00:00
|
|
|
$XMLDiskItem.SelectSingleNode('rasd:InstanceID', $NS).InnerText = $InstanceID
|
2021-05-19 08:03:52 +00:00
|
|
|
[void]$XML.SelectSingleNode('//ns:VirtualHardwareSection', $NS).InsertAfter(
|
|
|
|
$XMLDiskItem,
|
2021-05-19 09:11:09 +00:00
|
|
|
$XML.SelectSingleNode("//ns:VirtualHardwareSection/ns:Item/rasd:InstanceID[.='$($HighestInstanceID)']", $NS).ParentNode
|
2021-05-19 08:03:52 +00:00
|
|
|
)
|
2021-05-11 13:13:14 +00:00
|
|
|
|
2021-05-10 13:17:29 +00:00
|
|
|
$OVFConfig.PropertyCategories[0].ProductProperties += @{
|
|
|
|
Key = "vmconfig.disksize.$($DiskId)"
|
2021-05-11 13:13:14 +00:00
|
|
|
Type = If ([boolean]$Disk.Constraints.Minimum -or [boolean]$Disk.Constraints.Maximum) {
|
|
|
|
"Int($($Disk.Constraints.Minimum)..$($Disk.Constraints.Maximum))"
|
2021-05-10 13:17:29 +00:00
|
|
|
}
|
|
|
|
Else {
|
|
|
|
'Int'
|
|
|
|
}
|
|
|
|
Label = "Disk $($DiskId) size*"
|
2021-05-11 13:13:14 +00:00
|
|
|
Description = "$($Disk.Description) (in $($Disk.UnitSize))".Trim()
|
|
|
|
DefaultValue = "$($Disk.Constraints.Minimum)"
|
2021-05-10 13:17:29 +00:00
|
|
|
Configurations = '*'
|
|
|
|
UserConfigurable = 'true'
|
|
|
|
}
|
|
|
|
}
|
2021-05-11 13:13:14 +00:00
|
|
|
Write-Host "Inserted $($OVFConfig.DynamicDisks.Count) new node(s) into 'DiskSection' and 'VirtualHardwareSection' respectively"
|
2021-01-23 14:59:06 +00:00
|
|
|
|
|
|
|
If ($OVFConfig.DeploymentConfigurations.Count -gt 0) {
|
|
|
|
$XMLSection = $XML.CreateElement('DeploymentOptionSection', $XML.DocumentElement.xmlns)
|
|
|
|
$XMLSectionInfo = $XML.CreateElement('Info', $XML.DocumentElement.xmlns)
|
|
|
|
$XMLSectionInfo.InnerText = 'Deployment Type'
|
|
|
|
[void]$XMLSection.AppendChild($XMLSectionInfo)
|
|
|
|
|
|
|
|
ForEach ($Configuration in $OVFConfig.DeploymentConfigurations) {
|
|
|
|
$XMLConfig = $XML.CreateElement('Configuration', $XML.DocumentElement.xmlns)
|
|
|
|
|
2021-05-12 10:54:11 +00:00
|
|
|
[void]$XMLConfig.SetAttribute('id', $NS.LookupNamespace('ovf'), $Configuration.Id)
|
2021-01-23 14:59:06 +00:00
|
|
|
|
|
|
|
$XMLConfigLabel = $XML.CreateElement('Label', $XML.DocumentElement.xmlns)
|
|
|
|
$XMLConfigLabel.InnerText = $Configuration.Label
|
|
|
|
$XMLConfigDescription = $XML.CreateElement('Description', $XML.DocumentElement.xmlns)
|
|
|
|
$XMLConfigDescription.InnerText = $Configuration.Description
|
|
|
|
|
|
|
|
[void]$XMLConfig.AppendChild($XMLConfigLabel)
|
|
|
|
[void]$XMLConfig.AppendChild($XMLConfigDescription)
|
|
|
|
|
|
|
|
[void]$XMLSection.AppendChild($XMLConfig)
|
|
|
|
}
|
2021-05-10 13:17:29 +00:00
|
|
|
[void]$XML.SelectSingleNode('//ns:Envelope', $NS).InsertAfter($XMLSection, $XML.SelectSingleNode('//ns:NetworkSection', $NS))
|
2021-01-23 14:59:06 +00:00
|
|
|
Write-Host "Inserted 'DeploymentOptionSection' with $($Configuration.Count) nodes"
|
2021-05-11 11:00:12 +00:00
|
|
|
|
|
|
|
If ($OVFConfig.DeploymentConfigurations.Count -eq $OVFConfig.DeploymentConfigurations.Size.Count) {
|
2021-05-12 13:25:29 +00:00
|
|
|
# Create copies of existing 'Item/ResourceType' nodes
|
2021-05-11 11:00:12 +00:00
|
|
|
$XMLCPUTemplate = $XML.SelectSingleNode("//ns:VirtualHardwareSection/ns:Item/rasd:ResourceType[.='3']", $NS).ParentNode.CloneNode($True)
|
|
|
|
$XMLMemoryTemplate = $XML.SelectSingleNode("//ns:VirtualHardwareSection/ns:Item/rasd:ResourceType[.='4']", $NS).ParentNode.CloneNode($True)
|
2021-05-12 13:25:29 +00:00
|
|
|
# Delete existing nodes
|
2021-05-11 11:00:12 +00:00
|
|
|
ForEach ($Node in $XML.SelectNodes("//ns:VirtualHardwareSection/ns:Item/rasd:ResourceType[.='3' or .='4']", $NS).ParentNode) {
|
2021-05-12 10:54:11 +00:00
|
|
|
[void]$Node.ParentNode.RemoveChild($Node)
|
2021-05-11 11:00:12 +00:00
|
|
|
}
|
2021-05-12 13:25:29 +00:00
|
|
|
# Add adjusted 'Item/ResourceType' nodes
|
2021-05-11 11:00:12 +00:00
|
|
|
ForEach ($Configuration in $OVFConfig.DeploymentConfigurations) {
|
|
|
|
$XMLCPU = $XMLCPUTemplate.CloneNode($True)
|
2021-05-12 07:53:10 +00:00
|
|
|
[void]$XMLCPU.SetAttribute('configuration', $NS.LookupNamespace('ovf'), $Configuration.Id)
|
2021-05-11 11:00:12 +00:00
|
|
|
$XMLCPU.SelectSingleNode('rasd:ElementName', $NS).InnerText = '{0} virtual CPU(s)' -f $Configuration.Size.CPU
|
|
|
|
$XMLCPU.SelectSingleNode('rasd:VirtualQuantity', $NS).InnerText = $Configuration.Size.CPU
|
|
|
|
|
|
|
|
$XMLMemory = $XMLMemoryTemplate.CloneNode($True)
|
2021-05-12 07:53:10 +00:00
|
|
|
[void]$XMLMemory.SetAttribute('configuration', $NS.LookupNamespace('ovf'), $Configuration.Id)
|
2021-05-11 11:00:12 +00:00
|
|
|
$XMLMemory.SelectSingleNode('rasd:ElementName', $NS).InnerText = '{0}MB of memory' -f $Configuration.Size.Memory
|
|
|
|
$XMLMemory.SelectSingleNode('rasd:VirtualQuantity', $NS).InnerText = $Configuration.Size.Memory
|
|
|
|
|
2021-05-19 08:03:52 +00:00
|
|
|
[void]$XML.SelectSingleNode('//ns:VirtualHardwareSection', $NS).InsertAfter(
|
|
|
|
$XMLCPU,
|
|
|
|
$XML.SelectSingleNode('//ns:VirtualHardwareSection/ns:System', $NS)
|
|
|
|
)
|
|
|
|
[void]$XML.SelectSingleNode('//ns:VirtualHardwareSection', $NS).InsertAfter(
|
|
|
|
$XMLMemory,
|
|
|
|
$XML.SelectSingleNode('//ns:VirtualHardwareSection/ns:System', $NS)
|
|
|
|
)
|
2021-05-11 11:00:12 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-23 14:59:06 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 09:38:39 +00:00
|
|
|
[void]$XML.SelectSingleNode('//ns:VirtualHardwareSection', $NS).SetAttribute('transport', $NS.LookupNamespace('ovf'), 'com.vmware.guestInfo')
|
2021-01-23 14:59:06 +00:00
|
|
|
ForEach ($ExtraConfig in $OVFConfig.AdvancedOptions) {
|
|
|
|
$XMLExtraConfig = $XML.CreateElement('vmw:ExtraConfig', $XML.DocumentElement.vmw)
|
|
|
|
|
2021-05-12 09:38:39 +00:00
|
|
|
[void]$XMLExtraConfig.SetAttribute('required', $NS.LookupNamespace('ovf'), "$([boolean]$ExtraConfig.Required)".ToLower())
|
|
|
|
[void]$XMLExtraConfig.SetAttribute('key', $NS.LookupNamespace('vmw'), $ExtraConfig.Key)
|
|
|
|
[void]$XMLExtraConfig.SetAttribute('value', $NS.LookupNamespace('vmw'), $ExtraConfig.Value)
|
2021-05-12 10:54:11 +00:00
|
|
|
|
2021-05-10 13:17:29 +00:00
|
|
|
[void]$XML.SelectSingleNode('//ns:VirtualHardwareSection', $NS).AppendChild($XMLExtraConfig)
|
2021-01-23 14:59:06 +00:00
|
|
|
}
|
2021-05-12 13:25:29 +00:00
|
|
|
Write-Host "Added $($OVFConfig.AdvancedOptions.Count) 'vmw:ExtraConfig' node(s)"
|
2021-01-23 14:59:06 +00:00
|
|
|
|
2021-05-10 13:17:29 +00:00
|
|
|
$XMLProductSection = $XML.SelectSingleNode('//ns:ProductSection', $NS)
|
2021-01-23 14:59:06 +00:00
|
|
|
If ($XMLProductSection -eq $Null) {
|
|
|
|
$XMLProductSection = $XML.CreateElement('ProductSection', $XML.DocumentElement.xmlns)
|
2021-05-10 13:17:29 +00:00
|
|
|
[void]$XML.SelectSingleNode('//ns:VirtualSystem', $NS).AppendChild($XMLProductSection)
|
2021-01-23 14:59:06 +00:00
|
|
|
Write-Host "Inserted 'ProductSection'"
|
|
|
|
} Else {
|
2021-05-10 13:17:29 +00:00
|
|
|
ForEach ($Child in $XMLProductSection.SelectNodes('//ns:ProductSection/child::*', $NS)) {
|
2021-01-23 14:59:06 +00:00
|
|
|
[void]$Child.ParentNode.RemoveChild($Child)
|
|
|
|
}
|
|
|
|
Write-Host "Destroyed pre-existing children in 'ProductSection'"
|
|
|
|
}
|
|
|
|
$XMLProductSectionInfo = $XML.CreateElement('Info', $XML.DocumentElement.xmlns)
|
|
|
|
$XMLProductSectionInfo.InnerText = 'Information about the installed software'
|
|
|
|
[void]$XMLProductSection.AppendChild($XMLProductSectionInfo)
|
|
|
|
Write-Host "Inserted new 'Info' into 'ProductSection'"
|
|
|
|
|
|
|
|
ForEach ($Category in $OVFConfig.PropertyCategories) {
|
|
|
|
If ($Category.Name -ne '') {
|
|
|
|
$XMLCategory = $XML.CreateElement('Category', $XML.DocumentElement.xmlns)
|
|
|
|
$XMLCategory.InnerText = $Category.Name
|
|
|
|
[void]$XMLProductSection.AppendChild($XMLCategory)
|
|
|
|
Write-Host "Inserted new 'Category' into 'ProductSection'"
|
|
|
|
}
|
|
|
|
|
|
|
|
ForEach ($Property in $Category.ProductProperties) {
|
|
|
|
$XMLProperty = $XML.CreateElement('Property', $XML.DocumentElement.xmlns)
|
|
|
|
|
2021-05-12 13:25:29 +00:00
|
|
|
[void]$XMLProperty.SetAttribute('key', $NS.LookupNamespace('ovf'), $Property.Key)
|
2021-01-23 14:59:06 +00:00
|
|
|
Switch -regex ($Property.Type) {
|
2021-03-24 10:26:05 +00:00
|
|
|
'^boolean' {
|
2021-05-12 10:54:11 +00:00
|
|
|
[void]$XMLProperty.SetAttribute('type', $NS.LookupNamespace('ovf'), 'boolean')
|
2021-01-23 14:59:06 +00:00
|
|
|
}
|
2021-03-24 10:26:05 +00:00
|
|
|
'^int' {
|
2021-05-12 10:54:11 +00:00
|
|
|
[void]$XMLProperty.SetAttribute('type', $NS.LookupNamespace('ovf'), 'uint16')
|
2021-01-23 14:59:06 +00:00
|
|
|
$Qualifiers = @()
|
2021-03-24 10:26:05 +00:00
|
|
|
If ($Property.Type -match '^int\((\d*)\.\.(\d*)\)') {
|
2021-01-23 14:59:06 +00:00
|
|
|
If ($Matches[1]) {
|
|
|
|
$Qualifiers += "MinValue($($Matches[1]))"
|
|
|
|
}
|
|
|
|
If ($Matches[2]) {
|
|
|
|
$Qualifiers += "MaxValue($($Matches[2]))"
|
|
|
|
}
|
2021-05-12 10:54:11 +00:00
|
|
|
[void]$XMLProperty.SetAttribute('qualifiers', $NS.LookupNamespace('ovf'), $Qualifiers -join ' ')
|
2021-01-23 14:59:06 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-24 10:26:05 +00:00
|
|
|
'^ip' {
|
2021-05-12 10:54:11 +00:00
|
|
|
[void]$XMLProperty.SetAttribute('type', $NS.LookupNamespace('ovf'), 'string')
|
|
|
|
[void]$XMLProperty.SetAttribute('qualifiers', $NS.LookupNamespace('vmw'), 'Ip')
|
2021-01-23 14:59:06 +00:00
|
|
|
}
|
2021-03-24 10:26:05 +00:00
|
|
|
'^password' {
|
2021-05-12 10:54:11 +00:00
|
|
|
[void]$XMLProperty.SetAttribute('type', $NS.LookupNamespace('ovf'), 'string')
|
|
|
|
[void]$XMLProperty.SetAttribute('password', $NS.LookupNamespace('ovf'), 'true')
|
2021-01-23 14:59:06 +00:00
|
|
|
$Qualifiers = @()
|
2021-03-24 10:26:05 +00:00
|
|
|
If ($Property.Type -match '^password\((\d*)\.\.(\d*)\)') {
|
2021-01-23 14:59:06 +00:00
|
|
|
If ($Matches[1]) {
|
|
|
|
$Qualifiers += "MinLen($($Matches[1]))"
|
|
|
|
}
|
|
|
|
If ($Matches[2]) {
|
|
|
|
$Qualifiers += "MaxLen($($Matches[2]))"
|
|
|
|
}
|
2021-05-12 10:54:11 +00:00
|
|
|
[void]$XMLProperty.SetAttribute('qualifiers', $NS.LookupNamespace('ovf'), $Qualifiers -join ' ')
|
2021-01-23 14:59:06 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-24 10:26:05 +00:00
|
|
|
'^string' {
|
2021-05-12 10:54:11 +00:00
|
|
|
[void]$XMLProperty.SetAttribute('type', $NS.LookupNamespace('ovf'), 'string')
|
2021-01-23 14:59:06 +00:00
|
|
|
$Qualifiers = @()
|
2021-03-24 10:26:05 +00:00
|
|
|
If ($Property.Type -match '^string\((\d*)\.\.(\d*)\)') {
|
2021-01-23 14:59:06 +00:00
|
|
|
If ($Matches[1]) {
|
|
|
|
$Qualifiers += "MinLen($($Matches[1]))"
|
|
|
|
}
|
|
|
|
If ($Matches[2]) {
|
|
|
|
$Qualifiers += "MaxLen($($Matches[2]))"
|
|
|
|
}
|
2021-05-12 10:54:11 +00:00
|
|
|
[void]$XMLProperty.SetAttribute('qualifiers', $NS.LookupNamespace('ovf'), $Qualifiers -join ' ')
|
2021-03-24 10:26:05 +00:00
|
|
|
} ElseIf ($Property.Type -match '^string\[(.*)\]') {
|
2021-05-12 10:54:11 +00:00
|
|
|
[void]$XMLProperty.SetAttribute('qualifiers', $NS.LookupNamespace('ovf'), "ValueMap{$($Matches[1] -replace '","', '", "')}")
|
2021-01-23 14:59:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-12 10:54:11 +00:00
|
|
|
[void]$XMLProperty.SetAttribute('userConfigurable', $NS.LookupNamespace('ovf'), "$([boolean]$Property.UserConfigurable)".ToLower())
|
|
|
|
|
2021-01-23 14:59:06 +00:00
|
|
|
If ($Property.Type -eq 'boolean') {
|
2021-05-12 10:54:11 +00:00
|
|
|
[void]$XMLProperty.SetAttribute('value', $NS.LookupNamespace('ovf'), "$([boolean]$Property.DefaultValue)".ToLower())
|
2021-01-23 14:59:06 +00:00
|
|
|
} Else {
|
2021-05-12 10:54:11 +00:00
|
|
|
[void]$XMLProperty.SetAttribute('value', $NS.LookupNamespace('ovf'), $Property.DefaultValue)
|
2021-01-23 14:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
If ($Property.Label) {
|
|
|
|
$XMLPropertyLabel = $XML.CreateElement('Label', $XML.DocumentElement.xmlns)
|
|
|
|
$XMLPropertyLabel.InnerText = $Property.Label
|
|
|
|
[void]$XMLProperty.AppendChild($XMLPropertyLabel)
|
|
|
|
}
|
|
|
|
If ($Property.Description) {
|
|
|
|
$XMLPropertyDescription = $XML.CreateElement('Description', $XML.DocumentElement.xmlns)
|
|
|
|
$XMLPropertyDescription.InnerText = $Property.Description
|
|
|
|
[void]$XMLProperty.AppendChild($XMLPropertyDescription)
|
|
|
|
}
|
|
|
|
|
|
|
|
If (($Property.Configurations.Count -eq 1) -and ($Property.Configurations -eq '*')) {
|
2021-05-12 10:54:11 +00:00
|
|
|
[void]$XMLProperty.SetAttribute('configuration', $NS.LookupNamespace('ovf'), $OVFConfig.DeploymentConfigurations.Id -join ' ')
|
2021-01-23 14:59:06 +00:00
|
|
|
} ElseIf ($Property.Configurations.Count -gt 0) {
|
2021-05-12 10:54:11 +00:00
|
|
|
[void]$XMLProperty.SetAttribute('configuration', $NS.LookupNamespace('ovf'), $Property.Configurations -join ' ')
|
2021-01-23 14:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
If ($Property.Value.Count -eq 1) {
|
2021-05-12 10:54:11 +00:00
|
|
|
[void]$XMLProperty.SetAttribute('value', $NS.LookupNamespace('ovf'), $Property.Value)
|
2021-01-23 14:59:06 +00:00
|
|
|
} ElseIf ($Property.Value.Count -gt 1) {
|
|
|
|
ForEach ($Value in $Property.Value) {
|
|
|
|
$XMLValue = $XML.CreateElement('Value', $XML.DocumentElement.xmlns)
|
|
|
|
|
2021-05-12 10:54:11 +00:00
|
|
|
[void]$XMLValue.SetAttribute('value', $NS.LookupNamespace('ovf'), $Value)
|
|
|
|
[void]$XMLValue.SetAttribute('configuration', $NS.LookupNamespace('ovf'), $Value)
|
2021-01-23 14:59:06 +00:00
|
|
|
|
|
|
|
[void]$XMLProperty.AppendChild($XMLValue)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[void]$XMLProductSection.AppendChild($XMLProperty)
|
|
|
|
}
|
|
|
|
Write-Host "Inserted $($Category.ProductProperties.Count) new node(s) into 'ProductSection'"
|
|
|
|
}
|
|
|
|
|
2021-05-12 10:54:11 +00:00
|
|
|
$XML.Save($SourceFile.FullName)
|