How Do I Get the Current Username in Windows Powershell?
14 Answers I Found It: $Env: Username There Is Also: $Env: Userdomain $Env: Computername 2 on Windows, You Can: [System. Security. Principal. Windowsidentity]...
How do I get the current username in Windows PowerShell?
14 Answers
I found it:
$env:UserName
There is also:
$env:UserDomain
$env:ComputerName
On Windows, you can:
[System.Security.Principal.WindowsIdentity]::GetCurrent().Name
I thought it would be valuable to summarize and compare the given answers.
Must Read
If you want to access the environment variable:
(easier/shorter/memorable option)
[Environment]::UserName-- @ThomasBratt$env:username-- @Eoinwhoami-- @galaktor