2 ways to List environment variables in command line windows

Environment variables are essential for storing folder or file paths with variable names. Establishing environment variables becomes crucial during the installation of applications such as Java, Tomcat, or Derby. If these variables are not set, the commands may not execute as expected.

Determining whether environment variables are set can be challenging for developers using the command line in Windows.

This article explores various methods to print Windows environment variables from the command line, including the use of the set command and Windows PowerShell’s Get-ChildItemEnv.

Using the set Command to Retrieve Environment Variable List

The set command in Windows is utilized to set environment variables for the command line scope.

The syntax is as follows


set VARIABLE=path/value

For instance, setting the JAVA_HOME to the JDK route is done with the following command:

set JAVA_HOME=c:\JDK1.9

The set command can also be used to list all environment variables by simply executing:

CommonProgramFiles=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramW6432=C:\Program Files\Common Files

If the list is extensive, it can be challenging to view on a single page. In such cases, the output can be redirected to a file or viewed page by page using the more command:

set | more

How do you print the environment variable list to a text file?

To print the environment variable list to a text file, the following command can be used:

C:\>set > output.txt

This will output the environment variables list to the output.txt file.

It’s important to note that administrative permission is required for this command, or it will result in an Access is denied error. To filter the list based on a keyword, use the following command:

If you want to filter the list, you can use the below command with the keyword

C:\>set derby

Using Get-ChildItem Env in Windows PowerShell

An alternative approach to list environment variables is through Windows PowerShell. Open PowerShell by pressing Windows + Run (R) and typing Windows PowerShell. Then, run the following command:

Get-ChildItem Env:


This article addresses the challenge faced by developers in identifying the environment list for Java, Derby, Maven installations, providing solutions through the set command and Windows PowerShell’s Get-ChildItem Env.