views:

1058

answers:

3

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

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

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

+4  A: 

Found the answer to my own question:

Use the .NET method to get the variable:

[Environment]::GetEnvironmentVariable("FOO.BAR")
Jesse Weigert
That only works if it's in `env:`.
Jay Bazuzi
+2  A: 

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

Shay Levy
+9  A: 

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

PS (STA-ISS) (1) > ${env:variable.with.dots} = "Hi there"

PS (STA-ISS) (2) > ${env:variable.with.dots}

Hi there

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

Thanks! I figured it was something simple!
Jesse Weigert