Print Environment Variables in PowerShell

💡TL;DR
To print environment variables in PowerShell, use Get-ChildItem cmdlet as below:

Environment variables store values used by the operating system and installed programs. For instance, the environment variable PATH contains a list of directories to search for executable files.

Some other environment variables in the Windows operating system are OS, APPDATA, COMPUTERNAME, USERNAME, HOMEDRIVE, etc. PowerShell allows you to access and manage these variables of the system.

You can view, add, change, and delete environment variables from the PowerShell console. In this tutorial, you will learn different methods to print environment variables using PowerShell.

Print Environment Variables in PowerShell using Get-ChildItem

The Get-ChildItem cmdlet displays the items and child items found in the specific location. For example, you can get the content of directories such as filenames and sub-directories.

The environment variables are stored in the Env: drive. You can use the Get-ChildItem to get all environment variables available in Env:.

To print all environment variables in PowerShell, you can run:

Output:

Print all environment variables in PowerShell

The Get-ChildItem has three aliases: dir, gci, and ls.

Output:

You can use any of these aliases and display the environment variables in PowerShell.

For example,

OR

OR

Print Environment Variables in PowerShell using Get-Item

The Get-Item cmdlet can also be used to print the system’s environment variables in PowerShell.

Run the Get-Item command followed by the env: drive.

Output:

Print environment variables in PowerShell

The Get-Item has an alias gi. So, you can also use:

Print Values of Environment Variables in PowerShell

If you want to get the values of a particular environment variable, you can use the following syntax.

For example, to print the value of the environment variable OS, you can run:

It returns a string value of the given environment variable.

Output:

Note: The environment variable names in Windows are not case-sensitive. But, they are case-sensitive in Linux and macOS.

Print Values of Environment Variables using Get-ChildItem

Another method to display the value of an environment variable is to use Get-ChildItem or its aliases.

To view the value of PATHEXT, execute this command.

In this article, we have discussed several methods to print environment variables and their values in PowerShell. The commands like Get-ChildItem, dir, ls, and gci come in handy when you need to know the system’s environment variables.

We hope this tutorial has helped you to get environment variables using PowerShell.

Was this post helpful?

Leave a Reply

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