Tip of the Day: Using environment variables with Windows PowerShell


Today’s Tip…

Getting environment variables in Windows has always been easy. Just bring up a CMD prompt and type ‘set’.

clip_image001

But what if I want to use an environment variable in Windows PowerShell? That’s easy too! Simply use ‘$env:<environment variable name>’. For example, if I wanted a variable that contains my computer name, I could use ‘$env:comptuername’ like this…

clip_image002

This will save me steps when scripting as I don’t have to query for my computer name and create a new variable for it. I can just use ‘$env:computername’. This works with all the environment variables.

Neat, huh?


Comments (8)

  1. David Fletcher says:

    That is neat. How do I get a list of available environment variables?

  2. DevilsOwn says:

    How do i get a variables content from another variable.
    Ex: $env:($env:)

    1. Romil Goyal says:

      Hi, did you get the answer to this?

    2. We reached out to the Product Group on this one. They don’t understand what you are trying to do. Can you provide additional information? The only thing that they thought might work is setting $A to the value of $B.

  3. Qua T. says:

    PERFECT!!!

  4. min says:

    How do we get in touch with you? I know you mentioned that you don’t look at old posts and I had a question about breaking the 2 tb barrier. I have tried everything but still believe that there is a way around it. I did the GPT and partition route but still running into problems. Sorry to ask on this blog.

    1. My colleague wrote a Tip of the Day specific to the 2TB limit in Windows Storage. Check out his post, and if you have any questions after that, feel free to post them on that post.

      https://blogs.technet.microsoft.com/askcore/2010/02/18/understanding-the-2-tb-limit-in-windows-storage/

Skip to main content