Howto use environment variables in PowerShell

When you use the Get-Variable cmdlet you’ll get a list of variables available in PowerShell.
This does not include the environment variables which are available on the Windows OS though, only the ones native to PowerShell.

One that is not included in this list, but is very much available in PowerShell is the $Env.

## Update thanks to Aleksandar Nikolic ##
The reason why this is not included in the list with variables is because it isn’t a variable; it’s a PSDrive.
You can find the PSDrives with the Get-PSDrive cmdlet.
## End of update ##

This allows you to call environment variables from PowerShell, and use them… like so:

An example that may be more familiar to you would be the computer name:

Leave a Reply

Your email address will not be published. Required fields are marked *