In Windows Server 2003/2008, administrators relied on Terminal Services Manager (tsadmin.msc) for monitoring remote desktop sessions. With Windows Server 2012, Microsoft replaced this with more modern tools while maintaining similar functionality through different interfaces.
Here are the most effective ways to view active RDP sessions in Windows Server 2012:
1. Using the Command Line
The most straightforward approach is through PowerShell or Command Prompt:
# PowerShell equivalent
query session /server:localhost
# Alternative PowerShell cmdlet
Get-RDUserSession -ConnectionBroker "localhost"
Sample output would show:
SESSIONNAME USERNAME ID STATE TYPE DEVICE
console 0 Conn wdcon
rdp-tcp#1 domain\jdoe 1 Active rdpwd
2. Remote Desktop Services Manager
While the classic Terminal Services Manager is gone, Server Manager includes RDS tools:
- Open Server Manager
- Navigate to Remote Desktop Services > Collections
- Select your collection and view the "Sessions" tab
3. Windows Admin Center
For modern administration:
1. Install Windows Admin Center
2. Connect to your Server 2012 instance
3. Navigate to Remote Desktop > Sessions
Here's a PowerShell script to monitor sessions across multiple servers:
$servers = "server1","server2","server2012"
foreach ($server in $servers) {
Write-Host "Active sessions on $server"
try {
query session /server:$server 2>&1
}
catch {
Write-Warning "Failed to query $server"
}
Write-Host "------------------------"
}
Beyond viewing, you can perform these actions:
- Reset a session:
Reset-RDUserSession -HostServer "server2012" -UnifiedSessionID 1
- Logoff a user:
logoff 1 /server:localhost
- Send message:
msg * /server:localhost "System maintenance in 15 minutes"
If you encounter "Error 5" (Access Denied) when querying sessions remotely:
- Ensure you're running as Administrator
- Check firewall rules for Remote Desktop Services ports
- Verify Remote Management is enabled:
Enable-PSRemoting -Force
The transition from Terminal Services Manager to current tools reflects Microsoft's shift toward:
- PowerShell-based administration
- Centralized management through Server Manager
- Web-based interfaces like Windows Admin Center
Windows Server 2012 marked a significant change in remote desktop management by deprecating the classic Terminal Services Manager (tsadmin.msc). This change left many sysadmins searching for alternative methods to track active RDP sessions. While the graphical tool is gone, we now have more powerful programmatic approaches.
The most efficient way to list logged-on users is through PowerShell. Here's a comprehensive script that provides detailed session information:
# Get all active Remote Desktop sessions
$sessions = qwinsta /server:$env:COMPUTERNAME
# Parse the output (alternative to qwinsta using WMI)
$RDSessions = Get-WmiObject -Namespace "root\cimv2\terminalservices" -Class Win32_TerminalServiceSession |
Where-Object { $_.State -eq 2 } |
Select-Object UserName, SessionId, SessionName, ConnectTime, DisconnectTime
# Display formatted output
$RDSessions | Format-Table -AutoSize
Using WMI Directly
For environments where PowerShell isn't available, you can use WMI directly:
wmic /namespace:\\root\cimv2\terminalservices path Win32_TerminalServiceSession where "State=2" get * /format:list
Query Session Command
The traditional command-line approach still works:
query session /server:SERVERNAME
For ongoing monitoring, you might want to create a persistent solution. Here's a sample script that logs session activity:
# Continuous session monitor
while ($true) {
$currentSessions = Get-WmiObject -Namespace "root\cimv2\terminalservices" -Class Win32_TerminalServiceSession
$activeSessions = $currentSessions | Where-Object { $_.State -eq 2 }
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$output = "$timestamp - Active Sessions: $($activeSessions.Count)"
Add-Content -Path "C:\temp\RDSessions.log" -Value $output
$activeSessions | ForEach-Object {
Add-Content -Path "C:\temp\RDSessions.log" -Value ("tUser: " + $_.UserName + " (ID: " + $_.SessionId + ")")
}
Start-Sleep -Seconds 300
}
When implementing these solutions in production:
- Always run with appropriate privileges (Administrator rights required)
- Consider using JEA (Just Enough Administration) for delegated access
- Audit log sensitive session information appropriately
If you encounter "Access Denied" errors:
- Verify you're running as Administrator
- Check Windows Remote Management (WinRM) is enabled
- Ensure the Remote Desktop Services WMI provider is installed