Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I know I can access environment variables in PowerShell using $Env. For example, I can access FOO with $Env:FOO.

I can't figure out how to access the environment variable called FOO.BAR.

$Env:FOO.BAR doesn't work. How can I access this from within PowerShell?

question from:https://stackoverflow.com/questions/312314/environment-variables-in-powershell-with-a-dot-in-the-name

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
145 views
Welcome To Ask or Share your Answers For Others

1 Answer

To access any kind of PowerShell variable where the name contains non-alphanumeric characters, use the ${…} notation as in:

${env:variable.with.dots} = "Hi there"
${env:variable.with.dots}

This works for variables in any drive (registry, filesystem, etc.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...