Re: ("Scripting.Dictionary") buffer

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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


.



Relevant Pages

  • Re: trying to understand fork and wait
    ... old habits based on learning to script in REXX on the ... > the child reads it. ... situation for me (drop through to bottom/go back to top of loop). ... just to keep a hold of the exit code. ...
    (comp.lang.perl.misc)
  • Re: Questions about perl daemons with child processes and open files / signals
    ... running as daemon which launch a child process. ... I need to run a perl script as a daemon. ... tcpdump output, but I decided to use a pipe ... the parent process. ...
    (comp.lang.perl.misc)
  • Heirarchical path to the net
    ... traced the path of a net from child or leaf cell to the parent. ... script was run and it used .sch files(we use Calibre, ... Why the script traced up is because some signals have fan outs. ... hiCreateAppForm( ...
    (comp.cad.cadence)
  • Re: New Security Features, Please Comment
    ... then call setuid/gid and then launch the script ... language. ... The idea is to not allow the child to change its own uid, ...
    (Linux-Kernel)
  • Re: Uninstall remotely
    ... It is possible to look in the registry and find the uninstall string and then use a .vbs script to remove it from all machines. ... please find below a script that I wrote to help you find the computers that have - in this case - LogMeIn installed: ... ' Array of subkey values ... ' Enumerate subkeys and look for matches in dictionary object. ...
    (microsoft.public.windows.group_policy)