Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

People also ask

Can environment variable have dot?

As the other posts point out, the most common shells do not allow for setting environment variables with periods in the name.

What is $_ in PowerShell?

The “$_” is said to be the pipeline variable in PowerShell. The “$_” variable is an alias to PowerShell's automatic variable named “$PSItem“. It has multiple use cases such as filtering an item or referring to any specific object.

How do I read an environment variable in PowerShell?

Environment variables in PowerShell are stored as PS drive (Env: ). To retrieve all the environment variables stored in the OS you can use the below command. You can also use dir env: command to retrieve all environment variables and values.


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'"