Search code examples
powershell

How to print environment variables to the console in PowerShell?


I'm starting to use PowerShell and am trying to figure out how to echo a system environment variable to the console to read it.

Neither of the below are working. The first just prints %PATH%, and the second prints nothing.

echo %PATH%
echo $PATH

Solution

  • Prefix the variable name with env:

    $env:path
    

    For example, if you want to print the value of environment value MINISHIFT_USERNAME, then command will be:

    $env:MINISHIFT_USERNAME
    

    In case the environment variable label contains characters otherwise interpreted as bareword token terminators (like . or - or ), qualify the variable path expression with {...}:

    ${env:MINISHIFT-USERNAME}
    

    You can also enumerate all variables via the env drive:

    Get-ChildItem env: