Search notes:

System.Environment (class)

System.Environment allows to query information about the current environment (such as environment variables) and platform and manipulate these.

Interesting properties and Methods

GetEnvironmentVariable()

The following simple example tries to demonstrate how the PATH environment variable can be determined with PowerShell:
$env:PATH="$env:PATH;p:\ath\to\foo\bar\baz"

$pathUser     = [Environment]::GetEnvironmentVariable('PATH', 'user'    )
$pathSystem   = [Environment]::GetEnvironmentVariable('PATH', 'machine' )
$pathProcess  = [Environment]::GetEnvironmentVariable('PATH', 'process' )

write-host "Paths of user:"    ; write-host ( $pathUser    -replace ';', "`n" )
write-host "Paths of system:"  ; write-host ( $pathSystem  -replace ';', "`n" )
write-host "Paths of process:" ; write-host ( $pathProcess -replace ';', "`n" )

GetFolderPath()

If $folder is a value of a member of the System.Environment+SpecialFolder enum, the text value for this path is returned by GetFolderPath($folder), as is demonstrated with the following PowerShell snippet:
PS C:\> [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::UserProfile)
C:\Users\Rene

MachineName

MachineName evaluates to the NetBIOS name of the local computer.

OSVersion

OSVersion returns an System.OperatingSystem object.

SetEnvironmentVariable()

SetEnvironmentVariable sets an environment variable permanently or for the current process:
[environment]::setEnvironmentVariable('USER_VAR'  , 'foo', 'user'   )
[environment]::setEnvironmentVariable('GLOBAL_VAR', 'bar', 'machine')
[environment]::setEnvironmentVariable('PROC_VAR'  , 'baz', 'process')

SystemDirectory

The value of the property Environment.SystemDirectory is the name of the fully qualified system directory, for example C:\Windows\System32.

Version

Version returns a System.Version object that corresponds to the version of the Common Language Runtime.

See also

The two static properties Is64BitOperatingSystem and Is64BitProcess.
The property NewLine stores the value for a new line ("\n" or "\r\n").
An example on how to iterate over the set of environment variables that is returned by GetEnvironmentVariables() is here.

Index