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
Trackbacks/Pingbacks