LoganDecker84
MIS
Hello
The bottom script is used ot retrieve the ManagedBy attribute of a Distribution List as part of our termination process. Since we have thousands of DL's, when we cannot afford to have the script loop thru each DL each time a username is called.(I realize I may have cause this by the placement of some items in the script.) What I would like to do is create a dictionary array that can be used to compare the managedby attribute to the names in the list when they are called but am having some trouble
Any ideas?
' Use a dictionary object to collect all the groups
Set objList = CreateObject("Scripting.Dictionary")
objList.CompareMode = vbTextCompare
'-------------------------Reads Text File for users
Const ForReading = 1
TxtFile = "C:\scripts\Group Membership\dn.txt"
Set objFSO = CreateObject("Scripting.filesystemObject")
Set objTextFile = objFSO.OpenTextFile(TxtFile, ForReading)
'-------------------------Writing Text File
Const ForWriting = 2
Const ForAppending = 8
TxtFile1 = "C:\scripts\Group Membership\outPut.txt"
Set objFSO1 = CreateObject("Scripting.filesystemObject")
Set objTextFile1 = objFSO1.OpenTextFile(TxtFile1, ForAppending)
' Determine configuration context and DNS domain from RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
' Use ADO to search Active Directory for ObjectClass nTDSDSA.
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOOBject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
strFilter = "(&(objectCategory=Group)(objectClass=group))"
strBase = "<LDAP://Domain Info Here>"
strAttributes = "distinguishedName,DisplayName,cn,managedby"
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
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
StrDN = objRecordSet.Fields("distinguishedName")
strManager = objRecordSet.Fields("managedby")
groupCN = objRecordSet.Fields("cn")
set objGroup = GetObject("LDAP://" & strDN)
WScript.Echo groupCN & ";" & StrManager
objRecordSet.MoveNext
Loop
objRecordSet.Close
'----------UserNames to compare-------------------
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.ReadLine
sam = strNextLine
Loop
objConnection.Close
Set objConnection = Nothing
if usr = "N" Then Wscript.Echo "FindUser " & sam & " - NOT found."
Set objCommand = Nothing
Set objRootDSE = Nothing
Set objRecordSet = Nothing
The bottom script is used ot retrieve the ManagedBy attribute of a Distribution List as part of our termination process. Since we have thousands of DL's, when we cannot afford to have the script loop thru each DL each time a username is called.(I realize I may have cause this by the placement of some items in the script.) What I would like to do is create a dictionary array that can be used to compare the managedby attribute to the names in the list when they are called but am having some trouble
Any ideas?
' Use a dictionary object to collect all the groups
Set objList = CreateObject("Scripting.Dictionary")
objList.CompareMode = vbTextCompare
'-------------------------Reads Text File for users
Const ForReading = 1
TxtFile = "C:\scripts\Group Membership\dn.txt"
Set objFSO = CreateObject("Scripting.filesystemObject")
Set objTextFile = objFSO.OpenTextFile(TxtFile, ForReading)
'-------------------------Writing Text File
Const ForWriting = 2
Const ForAppending = 8
TxtFile1 = "C:\scripts\Group Membership\outPut.txt"
Set objFSO1 = CreateObject("Scripting.filesystemObject")
Set objTextFile1 = objFSO1.OpenTextFile(TxtFile1, ForAppending)
' Determine configuration context and DNS domain from RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
' Use ADO to search Active Directory for ObjectClass nTDSDSA.
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOOBject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
strFilter = "(&(objectCategory=Group)(objectClass=group))"
strBase = "<LDAP://Domain Info Here>"
strAttributes = "distinguishedName,DisplayName,cn,managedby"
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
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
StrDN = objRecordSet.Fields("distinguishedName")
strManager = objRecordSet.Fields("managedby")
groupCN = objRecordSet.Fields("cn")
set objGroup = GetObject("LDAP://" & strDN)
WScript.Echo groupCN & ";" & StrManager
objRecordSet.MoveNext
Loop
objRecordSet.Close
'----------UserNames to compare-------------------
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.ReadLine
sam = strNextLine
Loop
objConnection.Close
Set objConnection = Nothing
if usr = "N" Then Wscript.Echo "FindUser " & sam & " - NOT found."
Set objCommand = Nothing
Set objRootDSE = Nothing
Set objRecordSet = Nothing