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 :
Get-ChildItem env:
You can use Get-Item to get the value of desired environment variable. Below, I get the current username :
Get-Item env:\USERNAME
or
(Get-Item env:\USERNAME).value
Second method
You can also list all the variables :
dir env:
or
ls env: