1

First, excuse my poor english :)

I've a little headache with the syntax of Get-Content -Replace

My code is :

(Get-Content $env:HIS_XMLPATH) -replace '<Password>(.*?)</Password>', '<Password>$env:HIS_PWD</Password>' | Set-Content C:\test.xml

And the result in the xml file is :

<Password>$env:HIS_PWD</Password> 

I just want the value of my environment variable, what the syntax to include it ?

Thanks a lot

1 Answers1

2

You need to put the environment variable inside double quotes so it can be expanded. Single quoted strings are not expandable:

... -replace '<Password>(.*?)</Password>', "<Password>$env:HIS_PWD</Password>"
Shay Levy
  • 121,444
  • 32
  • 184
  • 206