How to Print Environment Variables in Powershell: 4 Easy Tips

Use these quick steps to print environment variables in PowerShell

by Henderson Jayden Harper
Henderson Jayden Harper
Henderson Jayden Harper
Passionate about technology, Crypto, software, Windows, and everything computer-related, he spends most of his time developing new skills and learning more about the tech world. He also enjoys... read more
Reviewed by Alex Serban
Alex Serban
Alex Serban
Windows Server & Networking Expert
After moving away from the corporate work-style, Alex has found rewards in a lifestyle of constant analysis, team coordination and pestering his colleagues. Holding an MCSA Windows Server... read more
Affiliate Disclosure
  • 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

XINSTALL BY CLICKING THE DOWNLOAD FILE
To fix various PC problems, we recommend Restoro PC Repair Tool:
This software will repair common computer errors, protect you from file loss, malware, hardware failure and optimize your PC for maximum performance. Fix PC issues and remove viruses now in 3 easy steps:

  1. Download Restoro PC Repair Tool that comes with Patented Technologies (patent available here).
  2. Click Start Scan to find Windows issues that could be causing PC problems.
  3. Click Repair All to fix issues affecting your computer's security and performance
  • Restoro has been downloaded by 0 readers this month.

Windows is a vast Operating System with many features and built-in components that coordinates 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, PowerShell in any of the supported operating system platforms 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 ls env

  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 in PowerShell will print all environment variables on the console with their name and values sorted by the name field.

2. Use GetChildItem Env

  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 lines and press Enter: Get-ChildItem Env: | Sort Name

The above command in PowerShell will print all environment variables.

3. Use dir env

  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 environment name and environment variable value path.

4. Print all environment variables values to 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 lines 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 worked for you as well.

Still having issues? Fix them with this tool:

SPONSORED

If the advices above haven't solved your issue, your PC may experience deeper Windows problems. We recommend downloading this PC Repair tool (rated Great on TrustPilot.com) to easily address them. After installation, simply click the Start Scan button and then press on Repair All.

This article covers:Topics: