Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ldap_matching_rule_in_chain question/issue

Status
Not open for further replies.
Aug 15, 2006
14
US
Hi All

I need some help on a vbscript that uses ldap_matching_rule_in_chain to add all users whose top level manager into a
Distribution List. I have this portion working perfectly and it returns exactly what i needed but im stuck as to how to check if they are in a group and if not add them. It would also be nice to remove
those users that do not belong, but thats not a priority. Any help is greatly appreciated.

****************************
On Error Resume Next
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOOBject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://DC=company,DC=com>"
strFilter = "(&(&(objectClass=person))(&(objectClass=user))(|(employeeType=employee)(employeeType=contractor))(manager:1.2.840.113556.1.4.1941:=<ManagersDN>))"

strAttributes = "distinguishedName,sn,givenName,description,samAccountName,mail,manager"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 99999
objCommand.Properties("Timeout") = 300
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
Do Until objRecordSet.EOF
strDN = objRecordSet.Fields("distinguishedName")
strLastName = objRecordSet.Fields("sn")
strFirstName = objRecordSet.Fields("givenName")
strsam = objRecordSet.Fields("samAccountName")
strmanager = objRecordSet.Fields("manager")
Set objUser = GetObject("LDAP://" & strDN)
WScript.Echo strsam
objRecordSet.MoveNext
Loop
Set objRecordSet = Nothing
objConnection.Close
Set objCommand = Nothing
Set objRootDSE = Nothing

*****************************
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top