November 13th, 2019

PowerTip: Use Windows PowerShell to display all Environment variables

Doctor Scripto
Scripter

Summary: Doctor Scripto demonstrates how to use env: 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 the env: PowerShell drive to display all of the currently set Environment variables.

dir env:

PowerShell, Doctor Scripto, PowerTip, Sean Kearney

 

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

3 comments

Discussion is closed. Login to edit/delete existing comments.

Newest
Newest
Popular
Oldest
  • Alan McBeeMicrosoft employee

    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 ‘;’

  • 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.

  • Ray Megal

    Handy. I also like: ls env:\

'; block.insertAdjacentElement('beforebegin', codeheader); let button = codeheader.querySelector('.copy-button'); button.addEventListener("click", async () => { let blockToCopy = block; await copyCode(blockToCopy, button); }); } }); async function copyCode(blockToCopy, button) { let code = blockToCopy.querySelector("code"); let text = ''; if (code) { text = code.innerText; } else { text = blockToCopy.innerText; } try { await navigator.clipboard.writeText(text); } catch (err) { console.error('Failed to copy:', err); } button.innerText = "Copied"; setTimeout(() => { button.innerHTML = '' + svgCodeIcon + ' Copy'; }, 1400); }

Feedback