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

Viewed 14415

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?

3 Answers

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

Use the .NET method to get the variable:

[Environment]::GetEnvironmentVariable("FOO.BAR")

Use:

Get-WMIObject Win32_Environment -filter "name='foo.bar'"
Related