List all environment variables from the command line

WindowsCommand LineEnvironment VariablesPrompt

Windows Problem Overview


Is it possible to list all environment variables from a Windows' command prompt?

Something equivalent to PowerShell's gci env: (or ls env: or dir env:).

Windows Solutions


Solution 1 - Windows

Just do:

SET

You can also do SET prefix to see all variables with names starting with prefix.

For example, if you want to read only derbydb from the environment variables, do the following:

set derby 

...and you will get the following:

DERBY_HOME=c:\Users\amro-a\Desktop\db-derby-10.10.1.1-bin\db-derby-10.10.1.1-bin

Solution 2 - Windows

Jon has the right answer, but to elaborate a little more with some syntactic sugar..

SET | more

enables you to see the variables one page at a time, rather than the whole lot, or

SET > output.txt

sends the output to a file output.txt which you can open in Notepad or whatever...

Solution 3 - Windows

To list all environment variables in PowerShell:

Get-ChildItem Env:

Or as suggested by user797717 to avoid output truncation:

Get-ChildItem Env: | Format-Table -Wrap -AutoSize

Source: Creating and Modifying Environment Variables (Windows PowerShell Tip of the Week)

Solution 4 - Windows

Simply run set from cmd.

> Displays, sets, or removes environment variables. Used without parameters, set displays the current environment settings.

Solution 5 - Windows

You can use SET in cmd

To show the current variable, just SET is enough

To show certain variable such as 'PATH', use SET PATH.

For help, type set /?.

Solution 6 - Windows

Don't lose time. Search for it in the registry:

reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"

returns less than the SET command.

Solution 7 - Windows

As mentioned in other answers, you can use set to list all the environment variables or use

set [environment_variable] to get a specific variable with its value.

set [environment_variable]= can be used to remove a variable from the workspace.

Solution 8 - Windows

Non expanded variables -

User variables -

reg query HKEY_CURRENT_USER\Environment

System variables -

reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"

Expanded variables -

In CMD -

SET

In Powershell -

Source - https://devblogs.microsoft.com/scripting/powertip-use-windows-powershell-to-display-all-environment-variables/

dir env:

Solution 9 - Windows

If you want to see the environment variable you just set, you need to open a new command window.

> Variables set with setx variables are available in future command windows only, not in the current command window. (Setx, Examples)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNicola CossuView Question on Stackoverflow
Solution 1 - WindowsJonView Answer on Stackoverflow
Solution 2 - WindowsFetchez la vacheView Answer on Stackoverflow
Solution 3 - Windowsuser52028778View Answer on Stackoverflow
Solution 4 - WindowsGrant ThomasView Answer on Stackoverflow
Solution 5 - WindowsBoyce FieldView Answer on Stackoverflow
Solution 6 - WindowsPaweł PiwowarView Answer on Stackoverflow
Solution 7 - WindowsAbhishek GurjarView Answer on Stackoverflow
Solution 8 - WindowsHrishikesh KadamView Answer on Stackoverflow
Solution 9 - Windowscaptain pugetView Answer on Stackoverflow