1215

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

1

8 Answers 8

1674

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
Sign up to request clarification or add additional context in comments.

8 Comments

This prompts me for a name?
@KevinMeredith: All commands in the Windows shell are case insensitive.
@CMCDragonkai are you using powershell? It appears that it has hikacked set with one of its command-lets. This is one of its less useful features! I asked a question about disabling this here
This doesn't seem to work with cmd /c. /e:on flag also doesn't help.
This is not guaranteed to work. This requires command extensions to be enabled. They are enabled by default on newer windows, but not older ones, and they can be turned off.
|
227

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

1 Comment

it's actually built in to some functions as well. Dir for example will page with a /p.
190

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)

5 Comments

Even if I don't use PowerShell because it doesn't work for every cmd command, this is the only solution for a pretty printing (on 2 columns) without big efforts. To achieve the same behavior in cmd, you need something like this for /f "tokens=1,2 delims==" ... which becomes very complicated ...
To avoid output being truncated, I would use the following: Get-ChildItem Env: | Format-Table -Wrap -AutoSize
gci env: instead Get-ChildItem Env:, easier to remember
dir env: I find even easier to remember
Question specifically asks for a solution using command prompt, not powershell
94

Simply run set from cmd.

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

3 Comments

Doesn't seem to work these days (in 2021) ` $ set $ cmdlet Set-Variable at command pipeline position 1 $ Supply values for the following parameters: $ Name[0]: $ Set-Variable: Cannot bind argument to parameter 'Name' because it is an empty array. `
set is run in cmd, not Powershell @JayKilleen
So VERY very true @Grant! +1 But I think the MORE command option was to paginate. :D @JayKilleen and any other people: ---> Command Prompt CMD Answer: set | more (or in shortcut: set | more & pause) ---> PowerShell PS Answer: gci env: | Format-Table -Wrap -AutoSize -OR- Get-ChildItem Env: | Format-Table -Wrap -AutoSize
28

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:

3 Comments

set by itself doesn't work with Github Actions, but the reg query does!
Sorry @HrishikeshKadam - it doesn't work. Command: PS C:\Users\User> dir env Error Message: dir : Cannot find path 'C:\Users\User\env' because it does not exist... FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
@doloop The colon after "env" is required, so dir env: works, but not dir env.
14

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 /?.

1 Comment

How is this different from existing answers?
11

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.

2 Comments

although that might be true, one difference is that the registry query returns unexpanded REG_EXPAND_SZ keys. For example reg query "HKCU\Environment" shows me that my %TEMP% variable depends on the value of %USERPROFILE%, so if that value changes, so would the value for %TEMP%. In contrast, SET just returns "C:\Users\mpag\AppData\Local\Temp"
Why do you say "don’t lose time"? Isn’t writing "set" in the command prompt faster than "reg query ..."?
5

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)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.