1188

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

1651

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
7
  • 28
    This prompts me for a name? Commented Nov 14, 2013 at 19:14
  • 58
    @KevinMeredith: All commands in the Windows shell are case insensitive.
    – Jon
    Commented Nov 20, 2013 at 16:13
  • 15
    @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
    – JonnyRaa
    Commented Feb 27, 2014 at 14:09
  • This doesn't seem to work with cmd /c. /e:on flag also doesn't help.
    – arrowd
    Commented Jul 4, 2017 at 15:04
  • 1
    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.
    – John Lord
    Commented Dec 19, 2018 at 17:30
224

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
  • 1
    it's actually built in to some functions as well. Dir for example will page with a /p.
    – John Lord
    Commented Dec 19, 2018 at 17:28
180

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)

4
  • 4
    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 ... Commented Jan 14, 2016 at 9:12
  • 7
    To avoid output being truncated, I would use the following: Get-ChildItem Env: | Format-Table -Wrap -AutoSize
    – user797717
    Commented Nov 13, 2017 at 11:50
  • 5
    gci env: instead Get-ChildItem Env:, easier to remember
    – mati kepa
    Commented Sep 26, 2019 at 11:35
  • dir env: I find even easier to remember
    – baddy
    Commented Jun 18 at 13:52
95

Simply run set from cmd.

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

3
  • 1
    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. ` Commented Mar 2, 2021 at 4:11
  • 3
    set is run in cmd, not Powershell @JayKilleen Commented Dec 16, 2021 at 16:28
  • 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
    – do loop
    Commented Jan 29 at 3:57
25

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:
2
  • set by itself doesn't work with Github Actions, but the reg query does!
    – Nick
    Commented Dec 28, 2021 at 21:00
  • 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
    – do loop
    Commented Jan 29 at 4:02
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
  • 4
    How is this different from existing answers? Commented Sep 26, 2019 at 8:51
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
  • 2
    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"
    – mpag
    Commented Apr 27, 2017 at 23:48
  • 7
    Why do you say "don’t lose time"? Isn’t writing "set" in the command prompt faster than "reg query ..."? Commented Mar 2, 2020 at 13:42
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)

Not the answer you're looking for? Browse other questions tagged or ask your own question.