In Windows environments, identifying the username of the currently logged-in user is a common requirement for system administration, scripting, automation, and troubleshooting tasks. This information can help verify the active user context, manage user-specific settings, and simplify log analysis in multi-user systems. This tutorial provides 2 methods how to get username of current user on Windows.
Method 1 - CMD
The Command Prompt can display the username of the currently logged-in user using the built-in USERNAME environment variable.
echo %USERNAME%
Output example:
User
Method 2 - PowerShell
PowerShell can access the same environment variable with its own syntax.
$env:USERNAME
Leave a Comment
Cancel reply