Common Tasks

Get current user name

The Windows PowerShell environment provider lets you access Windows environment variable too. To display the value of an environment variable we can use the following syntax:


In this syntax, the dollar sign ($) indicates a variable and the drive name, "env:" indicates an environment variable.

These three variables will give us an info about current user, domain and computer:




There is also another interesting .NET class that will give us "domain\user"  value:


<< 1 | 2