How to use environment variables in Powershell?

Posted by on Nov 6, 2010 in Environment, Powershell | 0 comments

Sometimes you need to use an environment variable (eg. username, userprofile, computername, …) in Powershell.

The location where environment variables are stored is “env:”. This behaves similar to a hard or flash drive. You can list its content or browse it by using

dir env:

The output shows all existing environment variables you can use. But how to use them?

You can get every environment variable by using the get-content or for short gc cmdlet.

$computername = get-content env:computername
$username = gc env:username

List of environment variables in Windows 7 / XP

No Comments

Trackbacks/Pingbacks

  1. PowerShell Export-CSV turns lovely tables in to garbage | Thom's HeadSpace - [...] of the new things I learned was that you can’t use standard system environment variables like you could with…

Leave a Reply

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

Captcha: * Time limit is exhausted. Please reload CAPTCHA.