Submitted By: Farhan Siddiqi

Template script for adding Terminal Server accounts to a multiple computers.

Visual Basic
Edit|Remove
'ts2.vbs script
'Author: Farhan Siddiqi
'Date: October 11, 2005
'Purpose: Modifies the RDP permissions on all DCs in the designated domain so 
'	  that the Server Administrators and Backup Operators have RDP access.
Option Explicit
On error resume next

Dim objOU, objRootDSE, objRDP, objDC, objItem
Dim strContainer,strDNSDomain, strDNSSuffix
Dim intCounter
Dim colItems
Dim errResult

strDNSDomain = "DC=xx,DC=xx,DC=xx"      ' MODIFY THIS FOR OTHER DOMAINS
strDNSSuffix = "xxxxxxxx"		' MODIFY THIS FOR OTHER DOMAINS
strContainer = "OU=Domain Controllers"

WScript.Echo "testing"


set objOU =GetObject("LDAP://" & strDNSSuffix & "/" & strContainer & "," & strDNSDomain)
intCounter = 0
  For each objDC in objOU

    set objRDP = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & _
        objDC.cn & "." & strDNSSuffix & "/root/cimv2")
    set colItems = objRDP.ExecQuery("Select * from Win32_TSPermissionsSetting")

    For each objItem in colItems
      errResult = objItem.AddAccount("xxxx",1)
    next

    For each objItem in colItems
      errResult = objItem.AddAccount("xxxx",1)
    next
		
    intCounter = intCounter + 1
  next

WScript.Echo "Number of DCs changed = " & intCounter
WScript.Quit