PowerShell: Environment Variables

January 27, 2023

We can get a single variable.

PS> $env:path

Or get all of them at once.

PS> gci env:

However, since each environment variable result is truncated to a single line, you will not be able to see all of certain ones – like Path. Use below to wrap all the values to multiple lines.

PS> gci env: | format-table -wrap
PS> gci env: | ft -wrap   # Using alias

Set Environment Variables

To set an environment variable for the current session.

PS> $env:NewVar = "This is a new variable"

Once the PowerShell command window is closed, the variable will be lost. Also, the variable is not available to other command windows.