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 Answer 1

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>"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.