Get the Server Names
First, you'll need the names of all the RD Session Host servers. How you do this depends on whether the servers are in a domain or a workgroup. (The workgroup model will support both domains and workgroups, but the domain model doesn't work for workgroups because it depends on reading OU memberships.) In both cases, you'll collect the names of the RD Session Host servers and put them into a file.
Assuming that all identically configured RD Session Host servers are in the same OU, one way to do this is to query that OU and return its members, writing the names to a file. The companion media contains a Windows PowerShell script that does this (called Getservers.ps1), but you can also do this with VBScript (RDSHServerFarmNames.vbs on the companion media), as shown in the following code snippet.
' =====Configuration Area================ strRDSTextFile = "FarmServers.txt" strRDSLDAPPath = "LDAP://OU=ASH_RD_Farm1, DC=ash, DC=local" sScriptDirPath = "\\colfax\ash-company-files\IT\AUDIT\" ' =====End Configuration Area============ Set objRDSOU = GetObject(strRDSLDAPPath) objRDSOU.Filter = Array("Computer") ' =================================== ' If file exists add data, if not, then create file and add data Set objFSO = CreateObject("Scripting.FileSystemObject") If objFSO.FileExists(sScriptDirPath&strRDSTextFile) Then 'do nothing Else Set objRDSTextFile = objFSO.CreateTextFile(sScriptDirPath&strRDSTextFile) objRDSTextFile.Close End If Set objRDSTextFile = objFSO.OpenTextFile(sScriptDirPath&strRDSTextFile, ForWriting) For Each objRDSItem in objRDSOU strRDSComputer = objRDSItem.CN objRDSTextFile.WriteLinestrRDSComputer Next objRDSTextFile.Close WScript.Quit
This won't work in the workgroup scenario, because workgroups don't have OUs. In that case, you'll need to rely on the query termserver command, as in the following example. This is a bit more complicated, because the command-line tool returns some extra data and you'll need to remove it from the file. This section relies on both RDSHNames.bat and QueryRDSH.vbs on the companion media.
' =====Configuration Area================ objRDSBATFile = "\\colfax\ash-company-files\IT\scripts\RDSHNames.bat" ' =====End Configuration Area============ ' Run batch file query termserv ' requires batch file ' batch file code is: query termserv>\\colfax\ash-company-files\IT\scripts\RDSHNames.txt Set WSHShell = CreateObject("Wscript.Shell") WSHShell.Run (objRDSBATFile),0, True ' Query termserv command adds two lines of header info to file ' This removes this extraneous information ' =====Configuration Area================ strRDSFile = "\\colfax\ash-company-files\IT\scripts\RDSHNames.txt" ' =====Configuration Area================ Set objFSO = CreateObject("Scripting.FileSystemObject") Set objRDSFile = objFSO.OpenTextFile(strRDSFile, ForReading) Do until objRDSFile.AtEndOfStream objRDSFile.SkipLine objRDSFile.SkipLine strRDSLines = objRDSFile.ReadAll Loop objRDSFile.close ' Remove carriage return at end of file Set objNewRDSFile = objFSO.OpenTextFile(strRDSFile, ForWriting) objNewRDSFile.WritestrRDSLines Set objNewRDSFile = objFSO.OpenTextFile(strRDSFile, ForReading) strRDSLines = objNewRDSFile.ReadAll objNewRDSFile.close strFileContents = strRDSLines intLength = Len(strFileContents) strEndofString = Right(strFileContents, 2) If strEndofString = vbCrLf Then strFileContents = Left(strFileContents, intLength - 2) Set objNewRDSFile = objFSO.OpenTextFile(strRDSFile, ForWriting) objNewRDSFile.WritestrFileContents objNewRDSFile.Close End if Set objRDSFile = Nothing Set objNewRDSFile = Nothing 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