This page looks best with JavaScript enabled

PowerShell - Get Current User

 ·   ·  ☕ 1 min read

Actually, there are many ways to get name of the user, which is currently logged on, including built-in .NET commands.

But let’s keep our code clean and stick with native PowerShell.

To get just the user name:

1
"$env:username"

You might also need the domain:

1
"$env:userdomain"

Or both of them:

1
"$env:userdomain\$env:username"

Victor Zakharov
WRITTEN BY
Victor Zakharov
Web Developer (Angular/.NET)