we'd like to know the number of users logged on to a particular windows box and also in detail be able to monitor the health of that sessions. Information like user ID and login data and time is also crucial.
This script rocks for RDP session email reports. I know its unrelated to your request, sort of, but for this script is indispensable for my team in seeing all active sessions on servers.
# Import the Active Directory module for the Get-ADComputer CmdLet
Import-Module ActiveDirectory
# Get today's date for the report
$today = Get-Date
$arrayofStringsNonInterestedIn = "console" , "RDP" , "services"
# Setup email parameters
$subject = "ACTIVE SERVER SESSIONS REPORT - " + $today
$priority = "Normal"
$smtpServer = "mail.MackDonalds.com"
$emailFrom = "RDPSessions@MackDonalds.com"
$emailTo = "Ronald@MackDonalds.com"
# Create a fresh variable to collect the results. You can use this to output as desired
$SessionList = "ACTIVE SERVER SESSIONS REPORT - " + $today + "`n`n"
# Query Active Directory for computers running a Server operating system
$Servers = Get-ADComputer -Filter {OperatingSystem -like "*server*"}
# Loop through the list to query each server for login sessions
ForEach ($Server in $Servers) {
$ServerName = $Server.Name
# When running interactively, uncomment the Write-Host line below to show which server is being queried
Write-Host "Querying $ServerName"
# Run the qwinsta.exe and parse the output
$queryResults = (qwinsta /server:$ServerName | foreach { (($_.trim() -replace "\s+",","))} | ConvertFrom-Csv)
# Pull the session information from each instance
ForEach ($queryResult in $queryResults) {
$RDPUser = $queryResult.USERNAME
$sessionType = $queryResult.SESSIONNAME
$State=$queryResult.State
If ($queryResult.ID -eq "Disc") {
$RDPUser = $queryResult.Sessionname
$SessionType=" "
$State=$queryResult.ID
}
# We only want to display where a "person" is logged in. Otherwise unused sessions show up as USERNAME as a number
If (($RDPUser -match "[a-z]") -and ($RDPUser -ne $NULL) -and ($RDPUser -ne "Disc")) {
# When running interactively, uncomment the Write-Host line below to show the output to screen
Write-Host $ServerName logged in by $RDPUser on $sessionType
$SessionList = $SessionList + "`n`n" + $ServerName + " logged in by " + $RDPUser + " on " + $sessionType
# When running interactively, uncomment the Write-Host line below to see the full list on screen
#$SessionList
get-content $sessionlist | where {$arrayofStringsNonInterestedIn -notcontains $_}
Write-host $SessionList
$SessionList2 = ""
ForEach($l in $SessionList.split("`n")){
if ($l.Trim().Equals("")){continue}
if ($l.Contains("services")) {continue}
if ($l.Trim().EndsWith("on")) {$SessionList2 += $l + "`n"}
Write-host $SessionList2
# Send the report email
Send-MailMessage -To $emailTo -Subject $subject -Body $SessionList2 -SmtpServer $smtpServer -From $emailFrom -Priority $priority
Thank you for the script. Its just that I wanted to set up a dashboard in SolarWinds and I was wondering if this was something I could monitor using SolarWinds and how.
You're asking for something that a lot of people want.
Syskit has it - https://www.syskit.com/#products-panel
Exoprise has it - RDP and VDI Performance Monitoring | Exoprise
SolarWinds has a few templates -
Windows Remote Desktop Services (Session Host Role)
Remote Desktop (RDP) Activity