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

Categories

0 votes
198 views
in Technique[技术] by (71.8m points)

Environment variables in PowerShell with a dot (.) in the name

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

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

1 Answer

0 votes
by (71.8m points)

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.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...