How to Print Environment Variables in Powershell: 4 Easy Tips

Use these quick steps to print environment variables in PowerShell

Reading time icon 4 min. read


Readers help support Windows Report. We may get a commission if you buy through our links. Tooltip Icon

Read our disclosure page to find out how can you help Windows Report sustain the editorial team Read more

Key notes

  • Environment variables store data regarding the information used by the operating system and other programs.
  • You can access the environment variables with PowerShell in any supported operating system platform.
  • There are numerous syntaxes and commands for printing all environment variables in PowerShell.
powershell print environment variables

Windows is a vast Operating System with many features and built-in components that coordinate its processes and information.

These processes store the operating system’s information in the Environment Variables. Hence, we’ll take you through how to use PowerShell to print Environment Variables.

What is an environment variable?

Environment variables store information about the operating system’s and other programs’ data. It contains information about the operating system path and location of the Windows installation files. Also, it stores details of processes used by the operating system and other programs.

Furthermore, environment variables are usually stored in strings and can’t be empty. Likewise, environmental variables, unlike other variables, can be inherited by child processes. Hence, they store values essential and needed in both parent and child processes.

However, in any supported operating system platform, PowerShell can access, manage, and change environment variables. Also, the environment provider in Windows PowerShell allows you to get, clear, change, add, clear, and delete environment variables in the current console.

How do I print all environment variables in PowerShell?

1. Use the ls env command

  1. Left-click the Start button, type PowerShell, and click Run as administrator.
  2. Click Yes on the User Account Control prompt.
  3. Copy and paste the following line and press Enter: ls env:

The above command will provide the console’s PowerShell print path environment variable with their name and values sorted by the name field.

2. Use the GetChildItem Env command

  1. Left-click the Start button, type PowerShell, and click Run as administrator.
  2. Select Yes on the User Account Control prompt.
  3. Copy and paste the following line and press Enter: Get-ChildItem Env: | Sort Name

The above command in PowerShell will print all environment variables, sorted by name.

Once you get the list of environment variables list, you can easily edit them to customize your system settings. To know how to do that, read this guide.

3. Use the dir env command

  1. Right-click the Start button and select PowerShell (Admin) from the list.
  2. Type or paste the following command and press Enter: dir env:
  3. This command will print the environment variables with the environment name and environment variable value path.

4. Print all environment variables values to a file

  1. Left-click the Start button, type PowerShell, and click Run as administrator.
  2. Click Yes on the User Account Control prompt.
  3. Copy and paste the following line and press Enter: gci env: | sort-object name| Export-Csv -Path D:\env_variables.txt -NoTypeInformation
  4. Then use the Export-Csv command line to print all environment variables to the file. Copy and paste the following Export-Csv syntax and press Enter: Export-Csv      -InputObject <PSObject>      [[-Path] <String>]      [-LiteralPath <String>]      [-Force]      [-NoClobber]      [-Encoding <Encoding>]      [-Append]      [[-Delimiter] <Char>]      [-IncludeTypeInformation]      [-NoTypeInformation]      [-QuoteFields <String[]>]      [-UseQuotes <QuoteKind>]      [-WhatIf]      [-Confirm]      [<CommonParameters>]

The above command in PowerShell gets all environment variables with their name and values sorted by the name field. Then, use the Export-CSV to convert the objects into a series of Character-Separated Value (CSV) strings. After, it prints all environment variables to a file.

You can also check our guide on how to copy files to Remote Computers with PowerShell on Windows 11.

Moreover, we have a detailed guide about PowerShell not showing the full output and some fixes to get it working on Windows 11.

Do not hesitate to let us know which of the above methods also worked for you.

More about the topics: PowerShell