Windows environment variables store values that programs use for configuration, such as the current username, temporary-file location, and folders searched when you run commands. To view the value of one environment variable in Command Prompt (CMD), type echo %VARIABLE_NAME%. For example, echo %PATH% shows the effective PATH available to your current CMD process.
Quick answer: Display one variable in CMD
- Press Windows + R, enter cmd, and press Enter. You can also open Command Prompt through Windows Search.
- To display your current user name, type
echo %USERNAME%and press Enter. - For a different variable, replace
USERNAMEwith the variable name, keeping the % signs around it.
echo %USERNAME%
echo %USERPROFILE%
echo %TEMP%
echo %PATH%In CMD, environment variable names are not case-sensitive. Thus %PATH% and %path% refer to the same variable in a normal Windows environment. The values above are examples of the current process environment, so they can differ by user account or Command Prompt window.
Display all environment variables with SET
Use set without arguments to print the environment variables visible to the current Command Prompt process. This can be helpful when debugging an application’s configuration, but the output may contain private paths, account identifiers, or credentials. Do not paste the unredacted result into a public forum or ticket.
setTo view variables whose names begin with a prefix, use the prefix as an argument:
set USER
set JAVA
set PATHFor example, set JAVA can display JAVA_HOME if it exists. It can also show multiple matching names or report that no variable starts with that prefix. Microsoft’s SET command reference describes both listing and setting variables.
Check whether a variable is defined
If echo %VARIABLE_NAME% prints unexpected text or nothing useful, the variable may not be set in that CMD session. Try the set command with its full name or a distinctive prefix. A message saying the environment variable is not defined means it is absent from that process.
set JAVA_HOMEIf you are troubleshooting Java or another development tool, remember that setting JAVA_HOME is not the same as adding its executable folder to PATH. One can be correct while the other is missing.
CMD vs PowerShell: the syntax is different
In Windows PowerShell or PowerShell 7, environment variables use env:USERNAME
env:PATH
Get-ChildItem Env:
The last command lists environment variables accessible through PowerShell’s Env: drive. For more details, see Microsoft Learn: PowerShell environment variables.
Display PATH in a readable way
Windows PATH usually contains several directories separated by semicolons. To inspect them individually in PowerShell, split the current PATH on semicolons:
.env:VARIABLE_NAME
Why does the value differ from Environment Variables in Settings? CMD reads its process environment, which may include temporary changes and may not reflect a registry change made after that window opened.
Why are my Java or Python commands not recognized? Check both the related installation path and the
PATHvariable. A correct environment variable alone does not guarantee that every program has restarted or can find the executable.Can I display variables in a batch file? Yes. A
.bator.cmdscript can useecho %PATH%andset. Be aware that percent expansion in loops and parenthesized blocks has additional timing rules; use delayed expansion intentionally if needed.Summary
Use
echo %NAME%to see one value in CMD,setto list the current environment, anddisplays PATH, andenv:Path
Get-ChildItem Env:lists process environment variables. CMD's percent-sign expansion does not work as expected in PowerShell, and PowerShell'sis empty in PowerShell, check the user and machine scopes separately withenv:JAVA_HOME
[Environment]::GetEnvironmentVariable('JAVA_HOME','User')and[Environment]::GetEnvironmentVariable('JAVA_HOME','Machine'). A newly opened terminal usually picks up persistent changes; an already-running terminal may still have an old environment.To temporarily change PATH in the current CMD window, use
set "PATH=C:\\Tools;%PATH%"; in PowerShell use. These changes affect the current process and processes launched from it, not permanent system settings. Avoid usingenv:Path
setx PATHto rewrite an existing PATH: it can expand references and may truncate long values. For permanent changes, use System Properties → Advanced → Environment Variables, make a backup, and edit the appropriate user or system PATH entry. Do not publish full environment dumps because they may contain credentials.C P Gupta is a YouTuber and Blogger. He is expert in Microsoft Word, Excel and PowerPoint. His YouTube channel @pickupbrain is very popular and has crossed 9.9 Million Views.
