0

Is it possible to parse a string literal that contains an environmental variable without using Invoke-Expression? The string contents come from an external settings file and I want to minimize the possibility of an injection attack.

$string= '${env:USERPROFILE}\sub-directory'
# desired result: C:\Users\Name\sub-directory

Invoke-Expression ("Convert-Path " + $string) -OutVariable parsedString
2
  • @Matt $ExecutionContext.InvokeCommand.ExpandString($string) is exactly what I was looking for - many thanks! Commented Oct 27, 2015 at 3:12
  • No problem. It is the one I use much of the time. Commented Oct 27, 2015 at 3:12

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.