Here is a little snippet, update to suit your needs:
templates\AppSettings.config
ConfigValues.ps1
<add key="MyKey" value="$foo" />
run.ps1
$foo = 'MyValue'
$currentDir = (Get-Location -PSProvider FileSystem).ProviderPath
$currentDir
# Load the variables and values to our current scope
. ($currentDir + "/ConfigValues.ps1")
# Process all files in templates folder
foreach ($file in (dir "templates/*.*"))
{
$text = [IO.File]::ReadAllText($file)
$ExecutionContext.InvokeCommand.ExpandString($text) | out-file (Join-Path $pwd $file.name)
}
Write-Host "Done."
Things in powershell can be written very quickly and this is a great example.
No comments:
Post a Comment