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:
).
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
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...
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)
for /f "tokens=1,2 delims==" ...
which becomes very complicated ...
Jan 14, 2016 at 9:12
Get-ChildItem Env: | Format-Table -Wrap -AutoSize
Nov 13, 2017 at 11:50
Simply run set
from cmd
.
Displays, sets, or removes environment variables. Used without parameters, set displays the current environment settings.
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
reg query HKEY_CURRENT_USER\Environment
reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
SET
dir env:
set
by itself doesn't work with Github Actions, but the reg query
does!
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
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 /?
.
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.
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"
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)