PowerTip: Use Windows PowerShell to display all Environment variables

Doctor Scripto

Dr Scripto

Summary: Doctor Scripto demonstrates how to use [System.Environment] to show all currently set environment variables

A picture containing scissors  Description automatically generated

Question: Hey Doctor Scripto, I remember in DOS if I wanted to see the values of all the Environment variables; like TEMP I could just type the SET Command. How do I do this in PowerShell?

Answer: You can do this in one line using [System.Environment] to display all of the currently set Environment variables.

[System.Environment]::GetEnvironmentVariables()

PowerShell, Doctor Scripto, PowerTip, Sean Kearney

 

Doctor Scripto
Dr Scripto

Scripter, PowerShell, vbScript, BAT, CMD

Follow Dr Scripto   

3 comments

  • Avatar
    Jarno Peschier

    When PowerShell is locked down in safe mode, you are not allowed to call methods on object for security reasons, so using System.Environment is out of the question then. The right way to get to environment variables in PowerShell is the Env: PSDrive. The requested “set” equivalent would just be “dir env:”. This should always work, even if calling methods on object is disallowed, I think.

  • Avatar
    Alan McBee

    A few shorter ways (all the same, just different aliases)
    dir env:
    gci env:
    ls env:
    All are aliased to
    Get-ChildItem env:

    Also, you can do this:
    cd env:

    Which keeps your current location in the Environment provider. Just use
    CD c:
    (or its alias, sl c: )
    to get back.

    Another fun party trick? Try this:
    $env:path – split ‘;’

Leave a comment