From 936e95ae62e3f060fcb26e0f25baacb17bd28d4b Mon Sep 17 00:00:00 2001 From: Dmitry Teselkin Date: Fri, 1 Mar 2013 19:38:44 +0400 Subject: [PATCH] Simple function for working with templates added --- .../CoreFunctions/include/Functions.ps1 | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Deployment/WindowsPowerShell/Modules/CoreFunctions/include/Functions.ps1 b/Deployment/WindowsPowerShell/Modules/CoreFunctions/include/Functions.ps1 index 698d1f0..77a7f8f 100644 --- a/Deployment/WindowsPowerShell/Modules/CoreFunctions/include/Functions.ps1 +++ b/Deployment/WindowsPowerShell/Modules/CoreFunctions/include/Functions.ps1 @@ -818,3 +818,30 @@ Function Get-ConfigDriveObject { } + +Function Expand-Template { + param ( + [String] $TemplateFile, + [String] $OutputFile, + [System.Collections.Hashtable] $ReplacementList, + [String] $Encoding = "Ascii" + ) + + if (-not [IO.File]::Exists($TemplateFile)) { + Write-Error "File '$TemplateFile' not exists" + return $null + } + + if ([IO.File]::Exists($OutputFile)) { + [IO.File]::Delete($OutputFile) + } + + Get-Content $TemplateFile -Encoding $Encoding | + ForEach-Object { + $Line = $_ + foreach ($Key in $ReplacementList.Keys) { + $Line = $Line.Replace("%_$($Key)_%", $ReplacementList[$Key]) + } + Add-Content -Path $OutputFile -Encoding $Encoding -Value $Line + } +}