1

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?

Paul Floyd
  • 5,530
  • 5
  • 29
  • 43
zar3bski
  • 2,773
  • 7
  • 25
  • 58
  • 3
    `Get-Content` returns a string array (one string per line). Use `$template = Get-Content DEV.properties -Raw` instead to read the whole template as a single multi-line string – Mathias R. Jessen Oct 21 '20 at 15:20

1 Answers1

0
$expanded = $template | %{ $ExecutionContext.InvokeCommand.ExpandString($_) }
coreps
  • 41
  • 4