Context
I have a multi line file named DEV.properties
. It contains references to ENV variables
ACTIVEMQ_DB_USERNAME=${ACTIVEMQ_DB_USERNAME}
I am writing a ps script to replace this file with one populated with the relevant variables
Problem
Here is how I proceed
#first load variables from a file
Get-Content C:\somewhere\over\the\rainbow\.credentials | Foreach-Object{$var = $_.Split('=');New-Variable -Name $var[0] -Value $var[1]}
$template = Get-Content DEV.properties
$expanded = $ExecutionContext.InvokeCommand.ExpandString($template)
Substitution is successful but while $template
is a multi line string, all CRLF seems to have disappeared from $expanded
. How can I fix it? Is there a more direct approach than looping though all lines?