How To Access Environment Variables In PowerShell

Because I can never seem to remember this stuff.

Basics

Magical Environment Variable:

$Env

Doesn’t do much on its own though.

List all available properties:

Get-ChildItem $Env:

Note to self: Remember to put that blasted colon at the end, and it will save you hours of figuring out why it lists your current folders instead.

Notable Properties

Get the local computer name:

$Env:COMPUTERNAME

Get the processor attributes:

$Env:NUMBER_OF_PROCESSORS
$Env:PROCESSOR_ARCHITECTURE
$Env:PROCESSOR_IDENTIFIER
$Env:PROCESSOR_LEVEL
$Env:PROCESSOR_REVISION

Get the Operating System type:

$Env:OS

Get the executable search path (just like PATH in DOS):

$Env:PATH

Get the TEMP path:

$Env:TEMP

Get user related information:

$Env:USERDNSDOMAIN
$Env:USERDOMAIN
$Env:USERNAME
$Env:USERPROFILE

Get the program files folders:

${Env:ProgramFiles}
${Env:ProgramFiles(x86)}

Index: PowerShell HowTo’s


Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s