diff --git a/scripts/Update-OvfConfiguration.ps1 b/scripts/Update-OvfConfiguration.ps1 index 1d75895..07908fa 100644 --- a/scripts/Update-OvfConfiguration.ps1 +++ b/scripts/Update-OvfConfiguration.ps1 @@ -22,7 +22,24 @@ $ConvertFromYamlSplat = @{ Yaml = $RawContent AllDocuments = $True } -$OVFConfig = ConvertFrom-Yaml @ConvertFromYamlSplat +$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 = @{