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?