Windows 7 / Getting Started

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
[Previous] [Contents] [Next]