PowerShell - Get Current User

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:

"$env:username"

You might also need the domain:

"$env:userdomain"

Or both of them:

"$env:userdomain\$env:username"