List Processes on the RD Session Host Servers
When you know the names of the RD Session Host servers in an OU, query each server by typing query process <executable> /server:<server name>. To make it easy, automate this process by running a batch file that runs the query process command against the saved server list and pipes that data to a file, as shown here.
FOR /F %%G IN (\\colfax\ash-company-files\IT\AUDIT\FarmServers.txt) DO query process * /server:%%G >>\\colfax\ash-company-files\IT\AUDIT\Processes\processes.txt
Why use a batch file? Mostly because it's easy. There's no reason to reinvent the wheel and try to pull all the process data from all the servers when query process does the same thing so succinctly. This batch file is on the companion media as Processes.bat.
Extract the Application Name
When you saved to a file the list of all processes running on all servers in an OU, you will need to focus on the particular process for which you need a usage count. Run this script to keep only lines in the text file that contain the application name. In this script, you are looking for Excel.exe, but you can edit the script to adjust the application name as required. The script is on the companion media as ProcCleanup.vbs.
' =====Configuration Area================ sScriptDirPath = "\\colfax\ash-company-files\IT\AUDIT\" sFldrProcesses = "Processes" sProcDirectoryPath = sScriptDirPath& "\" &sFldrProcesses sProcessesTxt = "processes.txt" objProcessesFile = sProcDirectoryPath& "\" &sProcessesTxt objFindApp.Pattern = "excel.exe" ' =====End Configuration Area============ Set objFindApp = CreateObject("VBScript.RegExp") Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile(objProcessesFile, ForReading) Do Until objTextFile.AtEndOfStream strSearchString = objTextFile.ReadLine Set colMatches = objFindApp.Execute(strSearchString) If colMatches.Count> 0 Then For Each strMatch in colMatches strNewContents = strNewContents&strSearchString&vbCrLf Next End If Loop objTextFile.Close Set objTextFile = objFSO.OpenTextFile(objProcessesFile, ForWriting) objTextFile.WritestrNewContents objTextFile.Close WScript.Quit
In this tutorial:
- Managing Remote Desktop Session
- Introducing RD Session Host Management Tools
- Command-Line Tools
- Connecting Remotely to Servers for Administrative Purposes
- Managing RD Session Host Servers from Windows 7
- Organizing Servers and VMs in the Remote Desktop Services Manager
- Monitoring and Terminating Processes
- Terminating Applications
- Monitoring and Ending User Sessions
- Closing Orphaned Sessions
- Disconnecting Sessions
- Providing Help with Remote Control
- Enabling Remote Control via Group Policy
- Enabling Remote Control via RD Session Host Configuration
- Shadowing a User Session
- Troubleshooting Session Shadowing
- Preparing for Server Maintenance
- Sending Messages to Users
- Shutting Down and Restarting RD Session Host Servers
- Applying RDS Management Tools
- Get the Server Names
- List Processes on the RD Session Host Servers
- Auditing User Logons
- Closing Unresponsive Applications