string variable not substituted in multi-line string string variable not substituted in multi-line string powershell powershell

string variable not substituted in multi-line string


The colon is the scope character: $scope:$variable. PowerShell thinks you are invoking the variable $password from the scope $user. You might be able to get away with a subexpression.

$user="arun"$password="1234*"@"{        "proxy": "http://$($user):$($password)@org.proxy.com:80",        "https-proxy": "http://$($user):$($password)@org.proxy.com:80"}"@

Or you could use the format operator

$user="arun"$password="1234*"@"{{        "proxy": "http://{0}:{1}@org.proxy.com:80",        "https-proxy": "http://{0}:{1}@org.proxy.com:80"}}"@ -f $user, $password

Just make sure you escape curly braces when using the format operator.

You could also escape the colon with a backtick

$jsonStr = @"{        "proxy": "http://$user`:$password@org.proxy.com:80",        "https-proxy": "http://$user`:$password@org.proxy.com:80"}"@