Using System.Environment Class in PowerShell




In PowerShell you can use a lot of modules and classes of your machine. Built-in system class "System.Environment" allows you to get a lot of useful information about your machine. Its syntax is like this [System.Environment]::class_property or [System.Environment]::class_method.

Get machine name (pc name):

[System.Environment]::MachineName

 

Get Operating System Information  - Platform, service pack, version

[System.Environment]::OSVersion

 

Get new line symbol for your machine. You can use \n\r or its combinations or to use.NET properties to assign this value to a variable.

[System.Environment]::NewLine

 

Check if computer has started to shutdown

[System.Environment]::HasShutdownStarted

 

Get the system directory (usually C:\Windows\System32)

[System.Environment]::SystemDirectory

 

Get the user name

[System.Environment]::UserName

 

Get letters of all logical drives

[System.Environment]::GetLogicalDrives()

 

You can get a list of all environment variables using GetEnvironmentVariables

[System.Environment]::GetEnvironmentVariables()

GetEnvironmentVariables

GetEnvironmentVariables

Also you can create a new environment variable or overwrite an existing one

[System.Environment]::SetEnvironmentVariable("VariableName", "VariableValue")

 

 




No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment





MarkiMarta.com. Notes of web-specialist
Since 2009
18+