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)}