In Windows environments, especially on Windows Server systems, administrators frequently need to identify the currently logged-in user, active Remote Desktop (RDP) sessions, console sessions, and disconnected users. PowerShell and built-in Windows command-line utilities provide quick and reliable ways to retrieve this information.
This article explains multiple methods to check:
These commands are extremely useful for:
whoamiThe simplest command to identify the current user is:
whoami
SERVER01\Administrator
This command displays:
PowerShell can directly access Windows environment variables.
$env:USERNAME
Administrator
$env:COMPUTERNAME
SERVER01
"$env:COMPUTERNAME\$env:USERNAME"
SERVER01\Administrator
Use .NET classes inside PowerShell:
[System.Security.Principal.WindowsIdentity]::GetCurrent().Name
DOMAIN\AdminUser
query userOne of the most important commands for Windows Server administrators.
query user
or
quser
USERNAME SESSIONNAME ID STATE IDLE TIME LOGON TIME
Administrator console 1 Active none 5/23/2026 9:00 AM
User1 rdp-tcp#5 2 Active 2:15 5/23/2026 10:30 AM
User2 rdp-tcp#6 3 Disc 1:05 5/23/2026 8:00 AM
| Column | Description |
|---|---|
| USERNAME | Logged-in account |
| SESSIONNAME | Console or RDP session |
| ID | Session ID |
| STATE | Active or Disconnected |
| IDLE TIME | User inactivity duration |
| LOGON TIME | Login timestamp |
qwinstaAnother built-in utility for terminal services.
qwinsta
SESSIONNAME USERNAME ID STATE TYPE
services 0 Disc
console Administrator 1 Active
rdp-tcp#5 User1 2 Active
rdp-tcp#6 User2 3 Disc
quser and qwinsta| Command | Purpose |
|---|---|
| quser | Shows user-focused session details |
| qwinsta | Shows terminal session details |
| query user | Same as quser |
| query session | Similar to qwinsta |
Using WMI:
Get-WmiObject Win32_ComputerSystem | Select-Object UserName
UserName
--------
DOMAIN\AdminUser
Modern PowerShell method:
Get-CimInstance Win32_LogonSession
Advanced filtering can identify:
To identify specific RDP session IDs:
quser
Look under the ID column.
Example:
User1 rdp-tcp#5 2 Active
Here:
Useful for:
After identifying session ID:
logoff 2
This logs off session ID 2.
For Remote Desktop Servers:
query session
Command Prompt alternative:
echo %username%
or
whoami
Example:
@echo off
echo Current User: %username%
pause
Write-Host "Current User:"
whoamiWrite-Host "`nActive Sessions:"
query user
Before performing server changes:
whoami
quser
Find disconnected sessions:
query user
Then:
logoff <SessionID>
Monitoring logged-in users helps:
If quser or qwinsta fails:
Use elevated PowerShell:
Run as Administrator
PowerShell and built-in Windows utilities make it easy to identify:
Commands like:
whoami
quser
query user
qwinsta
are essential tools for every Windows administrator and IT engineer.
Understanding these commands improves: