PoshTip #4 – List all environment variables
Retrieving the list of current environment variables is very simply with PowerShell. The windows environment variables are mounted as PSDrive in PowerShell.
First method
Just run :
1 |
Get-ChildItem env: |
You can use Get-Item to get the value of desired environment variable. Below, I get the current username :
1 |
Get-Item env:\USERNAME |
or
1 |
(Get-Item env:\USERNAME).value |
Second method
You can also list all the variables :
1 |
dir env: |
or
1 |
ls env: |