PowerShell includes the environment variables to store information related to the operating system and the processors. These variables can create an impact and predict how a certain running process is going to behave in a computer. Moreover, PowerShell has the authority to modify, manage or access the environment variables.
This post will overview several methods to display the environment variables from PowerShell.
How to Display all Environment Variables From PowerShell?
These are the methods that can be utilized to display the environment variables:
Method 1: Get the Environment Variables in PowerShell Using “Get-PSDrive” Command
The “Get-PSDrive” cmdlet gives insight into how a PowerShell views the registry as a drive. Moreover, it is very helpful in finding the structure of a local disk.
In our scenario, it will help us to find the environment variables from PowerShell :
Blackboard:
Method 2: Get Environment Variables in PowerShell Using “Env:*” Command
The environment variables can be displayed by the use of the given command:
Blackboard:
Here:
- “Get-Childitem” cmdlet assists in getting one or more items from a specified location.
- “-Path” parameter is used by the Get-Childitem cmdlet to specify a specific directory path.
- “Env” cmdlet is used to print the environment variables.
- “|” piping takes the output from the previous command and then transfers it to the next command.
- “Sort-Object” is used to sort the objects based on the parameter provided. For instance, we have provided the “Name” parameter to align the objects in alphabetical order:
Method 3: Get the Environment Variables in PowerShell Using “gci env:*” Command
In case you want to output the environment variable along with its values, then execute the given command in PowerShell:
Blackboard:
“gci” is an alias of the “Get-Childitem”, used to get one or more items from a specified location:
The output confirms that the above command has displayed all the environment variables along with their values.
In order to sort the environment variables with respect to their names, run this command:
Blackboard:
Method 4: Get the Environment Variable in PowerShell Using “ls Env:” Command
The given command will help to print all the variables in the console:
Blackboard:
The given “ls” cmdlet is also the alias of the “Get-Childitem” cmdlet utilized for getting the environment variables:
Method 5: Get the Environment Variables in PowerShell Using “$env:PATH” Command
The “$env:PATH” cmdlet contains the list of directory locations the operating system usually looks for executable files. The directory paths are then separated by semicolons(;):
Blackboard:
That was all about listing out the environment variables from PowerShell.
Conclusion
The environment variables can be displayed in PowerShell by executing several commands. These commands include “Get-PSDrive”, “gci env:*”, “ls Env:”, “Get-Childitem -Path Env:* | Sort-Object Name” or “$env:PATH”. This post has presented several PowerShell commands to output environment variables in PowerShell.