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



Get Operating System Information  - Platform, service pack, version



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.



Check if computer has started to shutdown



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



Get the user name



Get letters of all logical drives



You can get a list of all environment variables using 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 Notes of web-specialist
Since 2009