cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
AZHockeyNut
Champion Sweeper III
is there a way to make a report that shows RDP sessions to a system, Active ones and disconnected sessions. When I remote to a server there are sometimes inactive(disconnected) sessions, I can see that if I go into taskmgr and then users. so is there a way to report on those sessions and how long they are?

I found a way to do it with Powershell but I would prefer to have it all tied into LanSweeper.
I found most of the code here (https://discoposse.com/2012/10/20/finding-rdp-sessions-on-servers-using-powershell/) to give them credit but the script failed for me and I had to modify it.


# Import the Active Directory module for the Get-ADComputer CmdLet
Import-Module ActiveDirectory
# Get today’s date for the report
$today = Get-Date
# Setup email parameters
$subject = “ACTIVE SERVER SESSIONS REPORT – ” + $today
$priority = “Normal”
$smtpServer = “mailserver”
$emailFrom = “lansweeper@yourdomain.com”
$emailTo = “you@yourdomain.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 -properties * -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
# 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)) {
# 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 }
}
}
# Send the report email
Send-MailMessage -To $emailTo -Subject $subject -Body $SessionList -SmtpServer $smtpServer -From $emailFrom -Priority $priority
# When running interactively, uncomment the Write-Host line below to see the full list on screen
# $SessionList

1 REPLY 1
Custance
Engaged Sweeper

AZHockeyNut.

Did you ever find a Lansweeper solution for this?

Thanks