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’.
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…
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?
- Anonymous
May 14, 2014
That is neat. How do I get a list of available environment variables? - Anonymous
January 12, 2015
Get-ChildItem Env:
http://windowsitpro.com/powershell/powershell-one-liner-getting-local-environment-variables - Anonymous
December 16, 2015
How do i get a variables content from another variable.
Ex: $env:($env:)- Anonymous
December 04, 2017
Hi, did you get the answer to this? - Anonymous
January 16, 2018
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.
- Anonymous
- Anonymous
March 01, 2017
PERFECT!!! - Anonymous
December 28, 2017
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.- Anonymous
January 17, 2018
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/
- Anonymous