Re: ("Scripting.Dictionary") buffer
- From: "Richard Mueller" <rlmueller-NOSPAM@xxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 9 Mar 2006 20:21:18 -0600
indyboy wrote:
I have two questions:
1) We have about 8000 users in our AD and this scripts stops half way
through
as if the buffer is full or something. Are there limits to the number
of items
the dictionary function will hold?
2) How do I query all the containers below the Users OU also?
***************************************************************
Dim objDictionary, objOU, objComputer, objItem
Set objDictionary = CreateObject("Scripting.Dictionary")
i = 0
Set objOU =
GetObject("LDAP://OU=Users,OU=Accounts,DC=Mydomain,DC=org")
For Each objComputer in objOU
objDictionary.Add i, objComputer.CN
i = i + 1
Next
For Each objItem in objDictionary
StrComputer = objDictionary.Item(objItem)
WScript.Echo strComputer
Next
Hi,
The limit probably depends on available memory. On a lab machine with 80 MB
RAM I managed to populate a dictionary object with 18,000 Distinguished
Names, so I don't think you reached the limit. My test script was slow,
taking several minutes, so perhaps you aborted your script before it
finished.
Dictionary objects are great for checking existence or uniqueness. I note
that in your snippet you reverse the normal (Key, Item) pair relationship.
Normally the user name would be the Key in the pair. The Key value must be
unique. I have used code similar to:
objDictionary.Add objComputer.sAMAccountName, True
where I know that sAMAccountName is unique. I don't care about the Item part
of the pair and simply assign the boolean True.
In your case the cn value may not be unique so you avoid a possible error by
assigning a dummy index value as the Key. However, this means you cannot use
the dictionary object to check for existence or uniqueness. In your snippet
you could simply output the names and forget the dictionary object, but I
suspect you have another purpose. Otherwise, you could use an array, or
simply output the names in the first For Each loop without saving them.
There are two ways to enumerate users in the container and all child
containers. Expanding on your example, you can code a recursive subroutine.
In brief:
objOU = GetObject("LDAP://OU=Users,OU=Accounts,DC=Mydomain,DC=org")
Call EnumUsers(objOU)
Sub EnumUsers(objParent)
' Sub to enumerate users in OU/Container and child containers.
' Filter on user objects.
objParent.Filter = Array("user")
' Enumerate users in OU/Container.
For Each objUser In objParent
Wscript.Echo objParent.cn
Next
' Filter on child OU/Containers.
objParent.Filter = Array("organizationalUnit", "container")
' Enumerate child OU/Containers and enumerate users.
For Each objChild In objParent
Call EnumUsers(objChild)
Next
End Sub
Another method would be to use ADO. You would specify the base of the search
as your OU=Users, Filter on user objects, retrieve cn (and whatever other
attributes you desire), and specify a scope of subTree, which means to
search the base and all child containers.
For more information on using ADO, see this link:
http://www.rlmueller.net/ADOSearchTips.htm
In your case (using the example in the link above):
strBase "LDAP://OU=Users,OU=Accounts,DC=Mydomain,DC=org"
strFilter = "(&(objectCategory=person)(objectClass=user))"
strAttributes = "cn"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
An example VBScript program that uses ADO to create a text file with the
Distinguished Name's of all users in the domain is linked here:
http://www.rlmueller.net/Create%20User%20List%202.htm
You could modify this by changing the base of the search and the attributes
retrieved as per above.
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
.
- References:
- ("Scripting.Dictionary") buffer
- From: indyboy
- ("Scripting.Dictionary") buffer
- Prev by Date: Re: File compare script running slowly.
- Next by Date: Re: Replacing a line in a text file
- Previous by thread: ("Scripting.Dictionary") buffer
- Next by thread: VBScript Security
- Index(es):
Relevant Pages
|