Loading...
X

How to display all environment variables at the Windows command prompt

This article will show you how to display all environment variables from the Windows command line.

PowerShell and CMD

First of all, you need to distinguish what kind of program you are working in. The first appeared CMD - Windows command line, shell. For many years, CMD was the only option for running on the Windows command line.

Then PowerShell came along. In the beginning, it was an environment that could be specially launched. In recent years, PowerShell has become more common, in the “Power User Menu”, which is invoked by the Win+x keyboard shortcut, PowerShell has replaced CMD. Also, the new Terminal uses PowerShell by default.

The commands for displaying all environment variables depend on whether you are in PowerShell or CMD, so you need to differentiate between them.

PowerShell looks like this:

Or like this:

That is, the command line prompt begins with “PS”.

And the CMD looks like this:

Or like this:

How to list all environment variables in PowerShell

In PowerShell, use one of the following commands:

gci env:
ls env:
dir env:

They are not only equivalent, in fact, they are just aliases for the same command. That is, there is no difference in their use.

How to display all environment variables in CMD

To display environment variables in CMD use the command:

SET

To cut the output in one screen with the ability to scroll through the list, use the following construction:

SET | more

To save the output to a file:

SET > output.txt

This text file, output.txt, can be opened in any editor such as Notepad.

To display the value of a specific variable, use the familiar set command with the variable name:

set VARIABLE

For instance:

set PATH

The set command prints the value of all variables that start with the line VARIABLE. For example, the previous command will print the values of the PATH and PATHEXT variables.

And the following command will print the values of all variables whose name begins with P:

set P

Note that command names on Windows are not case sensitive.


Leave Your Observation

Your email address will not be published. Required fields are marked *