How to Find and Reference Environment Variables in Windows PowerShell

In the classic Windows Command Processor, environment variables were referenced using “%” symbols surrounding the variable name. The environment variables were enumerated by simply typing “set” in the command prompt. This has changed considerably in PowerShell.

To find the currently set environment variables, open PowerShell and type the following:

Get-ChildItem Env:

Then to reference one of those items, simply append the “Name” value to $Env: in your command or script. E.g. type the following to change to the windows directory:

cd $env:windir

To elaborate on the options for the Get-ChildItem command, simply prepend it with “help”:

help Get-ChildItem

The Conversation

Follow the reactions below and share your own thoughts.

Leave a Reply

You may also like-

How to run your own PowerShell scripts / cmdletsBy default, Microsoft has prevented the running of custom PowerShell scripts, a.k.a. cmdlets, by setting the PowerShell "ExecutionPolicy" to "Restricted". This can be changed ...