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
James Dudley
  • 597
  • 1
  • 4
  • 14

0 Answers0