Home » How to List Environment Variables in PowerShell

How to List Environment Variables in PowerShell

To list all environment variables in PowerShell, use the Get-ChildItem cmdlet or dir on the env: PowerShell drive.

Method 1: Using Get-ChildItem Env: to List All Environment Variables

Get-ChildItem Env:

Method 2: Use the dir env: to List All Environment Variables

dir env:

Both these methods are used to retrieve all the environment variables and print environment variables with their values.

The following examples show how to use each method to list and print environment variables.

Using the Get-ChildItem Env: to List All Environment Variables

The Get-ChildItem cmdlet with Env: drive lists all variables defined in the current environment.

The following PowerShell script shows how to do it with syntax.

# Using the Get-ChildItem cmdlet
Get-ChildItem Env:

# Using the Get-ChildItem alias gci
gci env:

In this example, it lists all the environment variable names with their values.

The output of the above script is given below.

PowerShell list all environment variables
PowerShell lists all environment variables

The Get-ChildItem or its alias gci on the Env: drive retrieves all the environment variables.

gci env:

This command also displays all the environment variables.

Using the dir env: to List All Environment Variables

You can use the dir command on the env: PowerShell drive to display all the environment variables.

The following PowerShell script shows how to do it with syntax.

dir env:

The output of the above example prints the environment variables with their values.

PowerShell display all environment variables
PowerShell displays all environment variables

Conclusion

I hope the above article on how to list all environment variables in PowerShell using the Get-ChildItem and dir command on the env: drive is helpful to you.

You can find more topics about Active Directory tools and PowerShell basics on the ActiveDirectoryTools home page.