Wednesday, 28 May 2014

Expanding PowerShell variables

I had the situation where I wanted to include an environment variable in my configuration .xml.
Rather than inventing a substitution scheme I decided to use $ExecutionContext.InvokeCommand.ExpandString instead

e.g.
  $sourceString = "This is my computername: `${env:COMPUTERNAME}"
  $ExecutionContext.InvokeCommand.ExpandString($sourceString) 

No comments: