'# From the book "Managing Enterprise Active Directory Services"
'# ISBN: 0-672-32125-4
ON ERROR RESUME NEXT
Dim adsPath, user, passwd, server
server = "dc1"
user = "administrator@xyz.com"
passwd = "password"
' Get configuration naming context
Dim rootDSE
Set rootDSE = GetObject("LDAP://" & server & "/RootDSE")
adsPath = "<LDAP://" & server & "/" & _
rootDSE.Get("configurationNamingContext") & ">;"
' Find the server object for this DC
Dim criteria, properties, scope
strCriteria = "(&(objectClass=server)(objectCategory=server)" _
& "(cn=" & server & "));"
properties = "distinguishedName;"
scope = "SubTree"
Dim objConnect, objCommand, objRecordSet
Set objConnect = CreateObject("ADODB.Connection")
objConnect.Provider = "ADsDSOObject"
objConnect.Open "Active Directory Provider", user, passwd
Set objCommand = CreateObject("ADODB.Command")
Set objCommand.ActiveConnection = objConnect
'Set the query string
objCommand.CommandText = adsPath & criteria _
& properties & scope
'Execute the query
Set objRecordSet = objCommand.Execute
Dim numObjs
numObjs = objRecordSet.RecordCount
objRecordSet.MoveFirst
If numObjs = 1 then
Dim serverDN, nTDSSettingsDN, ntdsObj, ldapObj
serverDN = objRecordSet.Fields(0).Value
nTDSSettingsDN = "LDAP://" & server _
& "/cn=NTDS Settings," & serverDN
' Open the NTDS Settings object with the supplied credentials
Set ldapObj = GetObject("LDAP:")
Set ntdsObj = ldapObj.OpenDsObject(nTDSSettingsDN, _
user, _
passwd,1)
ntdsObj.Put "options",1
ntdsObj.SetInfo
If Err.Number then
Wscript.Echo "Error occurred when setting options attribute: " _
& Err.Description
Wscript.Quit
Else
Wscript.Echo "Enabled GC for server " & strServer
End If
Else
Wscript.Echo "Search did not return expected results: " _
& numObjs & " matching entries found"
End If
|