The EXE Advanced Sensor worked for us . We have several (35) RD Servers (2012) (Under the PRTG's Max of 50 Channels) and instead of having multiple sensor graphs, this script was created to scan all the servers and report back to one sensor graph. It works for Windows 2012 and 2008 servers.
Save this script to the C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML folder. (If the RDS.txt file can't be created when the script is run you may have to adjust the permissions on that folder.)
Add parameters/arguments to the sensor settings using quotes.
The QWinsta program reports all sessions to a text file.
The script than reads the text file and converts it into XML.
It creates a channel for Total users and each server with the number of logged in users. Options to include disconnected sessions and exclude user accounts. (Services account)
DIM XMLStart, XMLEnd, xmlResult, XmlTotal
DIM strRDServer, TotalUsers
Dim ArgObj, ARG
Set ArgObj = WScript.Arguments
XMLStart = "<?xml version=" & chr(34) & "1.0" & chr(34) & " encoding=" & chr(34) & "Windows-1252" & chr(34) & " ?>" & vbCRLF & "<prtg>" & vbCRLF
XMLEnd = "</prtg>" & vbCRLF
XMLResult = ""
for each ARG in ARGobj
strRDServer = UCase(trim(ARG))
'msgbox strRDServer
AllUsers()
next
xmlTotal = "<result>" & vbCRLF & "<channel>" & "All Remote Users" & "</channel>" & vbCRLF
xmlTotal = xmlTotal & "<value>" & TotalUsers & "</value>" & vbCRLF
xmlTotal = xmlTotal & "</result>"
XMLFinal = XMLStart & xmlTotal & xmlResult & XMLEnd
wscript.echo XMLFinal
Sub AllUsers
strError = ""
'msgbox strRDServer
Count = 0
xmlChannel = ""
xmlValue = ""
Set objShell = CreateObject("WScript.Shell")
cmdQuery = "%comspec% /c QWinsta.exe /server:" & strRDServer & " > rds.txt"
'msgbox cmdQuery
objshell.run cmdQuery,0,1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile1 = objFSO.OpenTextFile("rds.txt", 1)
Do Until objFile1.AtEndOfStream
strSessionID = objFile1.ReadLine
if left(trim(strSessionID),8) <> "services" Then
if inSTR(strSessionID,"Active") > 0 Then
Count = Count + 1
end if
if inSTR(strSessionID,"Disc") > 0 Then
if instr(trim(strSessionID),".") = 0 or instr(trim(strSessionID),"administrator") = 1 then
'strError = strError & vbCRLF & "Unknown user" & vbtab & replace(trim(strSessionID)," Disc","")
'Count = Count + 1 'Optional
else
Count = Count + 1
end if
end if
end if
Loop
TotalUsers = TotalUsers + Count
xmlChannel = "<channel>" & strRDServer & "</channel>" & vbCRLF
xmlValue = "<value>" & Count & "</value>" & vbCRLF
xmlResult = xmlResult & vbCRLF & "<result>" & vbCRLF & xmlChannel & xmlValue & "</result>" & vbCLRF
end sub
Add comment