A logo showing the text blog.marcnuri.com
Español
Home»Operations»Windows: List all environment variables (CMD, PowerShell)

Recent Posts

  • Fabric8 Kubernetes Client 8.0 is now available!
  • Fabric8 Kubernetes Client 7.9 is now available!
  • Eclipse JKube 1.20 is now available!
  • Project, Agent, Person: The Missing Axis of AI Coding Tools
  • Fabric8 Kubernetes Client 7.8 is now available!

Categories

  • Artificial Intelligence
  • Backend Development
  • Cloud Native
  • Engineering Insights
  • Frontend Development
  • JavaScript
  • Legacy
  • Operations
  • Personal
  • Pet projects
  • Quality Engineering
  • Tools

Archives

  • September 2026
  • July 2026
  • June 2026
  • May 2026
  • April 2026
  • March 2026
  • February 2026
  • January 2026
  • December 2025
  • October 2025
  • September 2025
  • July 2025
  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • August 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • July 2019
  • March 2019
  • November 2018
  • July 2018
  • June 2018
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • December 2017
  • October 2017
  • August 2017
  • July 2017
  • January 2017
  • May 2016
  • December 2015
  • November 2015
  • December 2014
  • November 2014
  • October 2014
  • March 2014
  • August 2012
  • February 2011
  • November 2008
  • June 2008
  • May 2008
  • April 2008
  • January 2008
  • November 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007
  • March 2007

Windows: List all environment variables (CMD, PowerShell)

2008-04-30 in Operations tagged Windows / PowerShell by Marc Nuri | Last updated: 2026-10-14
Versión en Español

Introduction

⁠

To list all environment variables in Windows, run set in the Command Prompt (cmd) or Get-ChildItem Env: in PowerShell. To print or check a single variable, run echo %NAME% in the Command Prompt or $env:NAME in PowerShell. To see the user and system variables Windows stores for new processes, open the Environment Variables dialog from System Properties (sysdm.cpl).

set, Get-ChildItem Env: and the Environment Variables dialog have worked the same way since Windows XP, and they still do in Windows 11. In this post, I'll show you how to list all environment variables in Windows, print a single one, tell user variables from system variables, and read the PATH, both from the command line and from the Windows GUI. I checked every command against Microsoft's documentation in October 2026, for Windows PowerShell 5.1 and PowerShell 7.6.7.

  • Quick reference
  • From cmd
  • From PowerShell
  • User and system variables
  • From the Windows Graphical User Interface (GUI)
  • The PATH variable
  • Why a new variable doesn't show up

Quick reference: Command Prompt and PowerShell

⁠
TaskCommand Prompt (cmd)PowerShell
List allsetGet-ChildItem Env:
Names starting with JAVAset JAVAGet-ChildItem Env:JAVA*
Print one variableecho %JAVA_HOME%$env:JAVA_HOME
Print the PATHpath$env:Path -split ';'
Stored user variablesreg query HKCU\Environment[Environment]::GetEnvironmentVariables('User')
Stored system variablesreg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"[Environment]::GetEnvironmentVariables('Machine')

Each process gets its own copy of the environment when it starts: the system variables (shared by every user), your user variables, and anything its parent process added. That's why set and Get-ChildItem Env: show what the current window sees, which can differ from what Windows has stored. On Windows, variable names are not case-sensitive: %PATH%, %Path% and $env:path all refer to the same variable.

How to list all environment variables from cmd

⁠

Open a new command prompt (Win+R, then type cmd and hit enter) and type:

cmd.exe
set

The command outputs a list of all the environment variable names and values separated by an equal sign (=).

A screenshot showing the output of the set command in Windows XP
A screenshot showing the output of the set command in Windows XP

Since Windows 11 version 22H2, Windows Terminal is the default console, so cmd opens in a Windows Terminal tab. The commands are the same: they depend on the shell (Command Prompt or PowerShell), not on the window that hosts it.

How to filter the output of set

⁠

If you pass set a name, it lists only the variables whose name starts with it:

cmd.exe
set JAVA

To search for a word anywhere in the names and values, pipe the output to findstr:

cmd.exe
set | findstr /i "path"

The command now outputs only the lines that contain the word path, such as Path and PATHEXT. Add the /i flag: findstr is case-sensitive by default, and in a default Windows installation the variable is called Path, so findstr "PATH" would skip it.

A screenshot showing the output of the set|findstr command in Windows XP
A screenshot showing the output of the set|findstr command in Windows XP

How to print (echo) or check a single environment variable in cmd

⁠

To print the value of a single variable, wrap its name in percent signs:

cmd.exe
echo %JAVA_HOME%

The Command Prompt replaces %JAVA_HOME% with the value of the variable before it runs echo. If the variable isn't defined, the Command Prompt leaves the text as it is and prints %JAVA_HOME%. To check whether a variable is defined, for example in a batch file, use if defined:

cmd.exe
if defined JAVA_HOME (echo JAVA_HOME is set) else (echo JAVA_HOME is not set)

How to list all environment variables from PowerShell

⁠

PowerShell is the newer command-line shell and scripting language for Windows, and it exposes the environment variables as a drive called Env:. PowerShell 1.0 came out in November 2006 as an optional download for Windows XP, and Windows 7 was the first Windows client to include it. As of October 2026, Windows 10 and Windows 11 ship Windows PowerShell 5.1, which opens with powershell, and the cross-platform PowerShell 7 installs alongside it, with the command pwsh. Every command in this section works in both.

PowerShell offers multiple ways to list all environment variables. The easiest one is to use the Get-ChildItem cmdlet.

Using Get-ChildItem

⁠

Open a new PowerShell prompt (Win+R, then type powershell and hit enter) and type:

PowerShell
Get-ChildItem Env:

The command outputs a list of all the environment variable names and values in a table format.

A screenshot showing the output of the PowerShell Get-ChildItem Env: command in Windows XP
A screenshot showing the output of the PowerShell Get-ChildItem Env: command in Windows XP

The table cuts long values short, like the Path in the screenshot. To see them whole, sort the list by name and format it as a list:

PowerShell
Get-ChildItem Env: | Sort-Object Name | Format-List

You can also filter by name with a wildcard, or by value with Where-Object:

PowerShell
Get-ChildItem Env:*JAVA*
Get-ChildItem Env: | Where-Object Value -like '*Java*'

Using one of the Get-ChildItem aliases

⁠

Typing Get-ChildItem is a bit long, so PowerShell offers some aliases to make it easier to use. You can use any of the following commands to get the same result:

  • gci Env:
  • dir Env:
  • ls Env: (the ls alias exists on Windows only; PowerShell on Linux and macOS leaves ls to the system command)
PowerShell
ls Env:

The command outputs the same as the Get-ChildItem Env: command.

A screenshot showing the output of the PowerShell ls Env: command in Windows XP
A screenshot showing the output of the PowerShell ls Env: command in Windows XP

The main advantage of the PowerShell approach is that you can provide many options to the cmdlet to customize its output for your needs.

How to get a single environment variable in PowerShell

⁠

To print the value of a single variable, prefix its name with $env::

PowerShell
$env:JAVA_HOME

The Command Prompt syntax doesn't work here: in PowerShell, echo %JAVA_HOME% prints the text %JAVA_HOME% as it is. If the variable doesn't exist, $env:JAVA_HOME prints nothing; to check whether it's defined, use Test-Path, which returns True or False:

PowerShell
Test-Path Env:JAVA_HOME

You can also read a variable through .NET, which is handy in scripts:

PowerShell
[Environment]::GetEnvironmentVariable('JAVA_HOME')

How to list user and system environment variables separately

⁠

Windows stores the variables you define in two places, and builds your sign-in environment from both:

  • System variables apply to every user, and only administrators can change them. Windows stores them in the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment registry key.
  • User variables apply to your account only. Windows stores them in the HKEY_CURRENT_USER\Environment registry key.

set and Get-ChildItem Env: show the merged result, plus variables Windows sets for each session, such as USERNAME and USERPROFILE, and anything set in the current window. To list each group on its own, pass a target to GetEnvironmentVariables in PowerShell:

PowerShell
[Environment]::GetEnvironmentVariables('User')
[Environment]::GetEnvironmentVariables('Machine')

The target can be Process (the current session, the default), User or Machine. The output isn't sorted; to sort it by name, enumerate it first:

PowerShell
[Environment]::GetEnvironmentVariables('User').GetEnumerator() | Sort-Object Name

From the Command Prompt, you can read the same registry keys with reg query:

cmd.exe
reg query HKCU\Environment
reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"

reg query prints the values as stored, so the system Path shows entries such as %SystemRoot%\system32 unexpanded.

How to check environment variables from the Windows Graphical User Interface (GUI)

⁠

If you don't need to use this output in a script, or you just prefer the Windows GUI, you can check the environment variables from the System Properties window.

In Windows 11 and Windows 10, the quickest way is to type environment in the Start menu search and open Edit the system environment variables. The same search also shows Edit environment variables for your account, which opens the Environment Variables dialog directly, without asking for administrator rights, to edit your user variables. You can also reach it from Settings > System > About > Advanced system settings. The Run dialog works in every version since Windows XP: press the Win+R keys, type sysdm.cpl and hit enter.

A screenshot of the Windows Run dialog in Windows XP
A screenshot of the Windows Run dialog in Windows XP

Next, click on the Advanced tab and then on the Environment Variables button.

A screenshot of the Windows System Properties dialog in Windows XP
A screenshot of the Windows System Properties dialog in Windows XP

The Environment Variables dialog will open. The upper list shows the user variables for your account, and the lower list shows the system variables. You need administrator rights to change the system variables.

A screenshot of the Windows Environment Variables dialog in Windows XP
A screenshot of the Windows Environment Variables dialog in Windows XP

The dialog shows what Windows stores, not what an open Command Prompt or PowerShell window sees: a value you change here only reaches the programs you start afterwards.

If you edit environment variables often, Microsoft's free PowerToys includes an Environment Variables utility that lists the user and system variables, lets you edit them, and shows the values that apply, Path included.

How to view the PATH environment variable

⁠

The PATH variable holds the list of directories where Windows looks for executables, separated by semicolons (;). In the Command Prompt, the path command with no arguments prints it, prefixed with PATH=:

cmd.exe
path

The value is a single long line, which is hard to read. In PowerShell, split it to print one directory per line:

PowerShell
$env:Path -split ';'

The Path of a session combines the system Path and your user Path. To see each of them on its own, read them with their target:

PowerShell
[Environment]::GetEnvironmentVariable('Path', 'Machine') -split ';'
[Environment]::GetEnvironmentVariable('Path', 'User') -split ';'

Why doesn't a new environment variable show up?

⁠

A process gets its environment when it starts, so a window that was already open doesn't see later changes.

  • set NAME=value in the Command Prompt and $env:NAME = 'value' in PowerShell change the current session only, and the change is gone when you close the window.
  • The Environment Variables dialog and the setx command store the variable in the registry, so it persists, but only programs you start afterwards see it. Open a new Command Prompt or PowerShell window; if the variable is still missing, close and reopen the terminal app or the editor you started it from.

Be careful with setx PATH "%PATH%;C:\Tools", a command you'll find in many guides: %PATH% expands to the system and user Path combined, setx writes all of it into your user Path, and it truncates any value longer than 1,024 characters. To add a directory to the PATH for good, edit the user or the system Path in the Environment Variables dialog instead. That's how I added Maven to the PATH in my guide to installing Apache Maven on Windows.

Conclusion

⁠

In this post, I have shown you the possible ways to list all environment variables in Windows, something you'll need sooner or later when developing or administrating a system. From the command line, set in the Command Prompt and Get-ChildItem Env: in PowerShell list every variable of the current session, and echo %NAME% or $env:NAME print a single one. [Environment]::GetEnvironmentVariables and reg query show the user and system variables Windows stores, and the plain old Environment Variables dialog shows both in the GUI. The core commands, set and Get-ChildItem Env:, have worked the same way since Windows XP, so they should work on whichever version you're on. I hope you find it useful.

You Might Also Like

⁠
  • How to install Apache Maven on Windows?
  • Windows: How to kill a process from the command line
  • How to check open TCP/IP ports in Windows
Twitter iconFacebook iconLinkedIn iconPinterest iconEmail icon

Post navigation
How to install Apache Maven on Windows?Windows: How to kill a process from the command line
© 2007 - 2026 Marc Nuri