From e44196a1a842a4a434a30ae672bba3c62ca6df21 Mon Sep 17 00:00:00 2001 From: djpbessems Date: Mon, 15 Feb 2021 09:53:53 +0100 Subject: [PATCH] Add missing parameter --- scripts/Update-OvfConfiguration.ps1 | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/scripts/Update-OvfConfiguration.ps1 b/scripts/Update-OvfConfiguration.ps1 index fd731de..ecbae0d 100644 --- a/scripts/Update-OvfConfiguration.ps1 +++ b/scripts/Update-OvfConfiguration.ps1 @@ -9,7 +9,8 @@ Param( Throw "'$_' is not a valid filename (within working directory '$PWD'), or access denied; aborting." } })] - [string]$OVFFile + [string]$OVFFile, + [hashtable]$Parameter ) $GetContentSplat = @{ @@ -21,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 = @{