[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

08/12/2008 at 12:34PM PDT, ID: 23642474
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.2

VBScript - Recursion Question (AD Browsing)

Asked by FirstDecan in VB Script, Active Directory, Microsoft Server

This is my first question on this forum, so please forgive any mistakes I may make.

I'm attempting to get the counts of all the groups in an Active Directory Domain by enumerating the groups through the ADSI LDAP provider. I have a routine that is setup to recursively browse the OUs\Containers in the domain, bind to the groups within each OU\Container, and then access the count (functioning code is attached).

The code functions, but runs very inefficiently. After the initial OUs\Containers are enumerated, child objects are enumerated recursively. The executable grows in memory size to almost 1.5GB and doesn't ever shrink back down. It seems as if the executable isn't releasing the memory used by a subroutine when the subroutine has completed.

My Question is this: Can someone tell me why the memory usage for this code is so out of control, and possibly suggest a remedy.

Side Notes: I am aware of other methods for enumerating group memberships, including the ADSI WinNT provider and using ADO Queries. I would like to get the method I am currently using (ADSI LDAP provider) at a more manageable state, because the ADSI LDAP provider has advantages the other methods do not. While I can appreciate other suggestions, my main concern is the high memory usage due to recursion.

Thank you, and Kind Regards.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
'===============================================================================
'===============================================================================
Dim objFSO      'File System Object
Dim objShell    'Windows Shell
Dim strDomain   'Domain to Enumerate (LDAP Path)
 
'-->Set the LDAP Path to the Domain
strDomain = "LDAP://FakeDomainName"
'-->Initialize basic variables
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("wscript.shell")
'-->Enumerate Domain Groups
GetBaseContainers
'-->Completion notification
MsgBox "Finito",,"Script Completion Notice"
 
'===============================================================================
'Sub GetBaseContainers
'===============================================================================
Sub GetBaseContainers
    On Error Resume Next
 
    Dim objDomain       'Domain Object instantiated
    Dim objOU           'Organizational Unit or container instantiated
 
    '-->Bind to the Domain
    Set objDomain = GetObject(strDomain)
    '-->DomainDNS object contains no groups, set the filter to OUs
    objDomain.Filter = Array("organizationalUnit")
    '-->Cycle through each OU and enumerate groups
    For Each objOU In objDomain
        EnumLDAPOU objOU.ADSPath,"FakeDomainName/" & Right(objOU.Name,Len(objOU.Name)-3)
    Next
    '-->DomainDNS object contains no groups, set the filter to Containers
    objDomain.Filter = Array("container")
    '-->Cycle through each container and enumerate groups
    For Each objOU In objDomain
        EnumLDAPOU objOU.ADSPath,"FakeDomainName/" & Right(objOU.Name,Len(objOU.Name)-3)
    Next
    '-->DomainDNS object contains no groups, set the filter to builtinDomain
    objDomain.Filter = Array("builtinDomain")
    '-->Cycle through each builtinDomain object and enumerate groups
    For Each objOU In objDomain
        EnumLDAPOU objOU.ADSPath,"FakeDomainName/" & Right(objOU.Name,Len(objOU.Name)-3)
    Next
End Sub
 
'===============================================================================
'Sub EnumLDAPOU
'===============================================================================
Sub EnumLDAPOU(LDAPPath,LDAPTrace)
    On Error Resume Next
 
    Dim objLDAPOU       'Organization unit object
    Dim objGroup        'Group object
    Dim strName         'The Name of the group
    Dim strPath         'The LDAP ADSPath of the group
    Dim intLDAPCount    'The number of members in the group
 
    '-->Bind to an AD OU
    Set objLDAPOU = GetObject(LDAPPath)
    '-->Look at just the groups in the OU
    objLDAPOU.Filter = Array("group")
    '-->Go through each group and get it's attributes
    For Each objGroup In objLDAPOU
        '-->Initilaize attribute variables
        strName = ""
        strPath = ""
        '-->Get the attribute variables
        strName = LCase(objGroup.SamAccountName)
        strPath = LCase(objGroup.ADSPath)
        strPath = Replace(strPath,"ldap://","LDAP://")
        '-->Get the membership count
        intLDAPCount = 0
        intLDAPCount = objGroup.Members.Count
        '--------------->
        'More Code is here to keep track of the counts
        '--------------->
    Next
    objGroup = Null
    '-->Enumerate any groups in this OU's Sub OUs
    objLDAPOU.Filter = Array("organizationalUnit")
    For Each objOU In objLDAPOU
        EnumLDAPOU objOU.ADSPath,LDAPTrace & "/" & Right(objOU.Name,Len(objOU.Name)-3)
    Next
    '-->Enumerate any groups in this OU's Sub OUs
    objLDAPOU.Filter = Array("container")
    For Each objOU In objLDAPOU
        EnumLDAPOU objOU.ADSPath,LDAPTrace & "/" & Right(objOU.Name,Len(objOU.Name)-3)
    Next
End Sub
 
'===============================================================================
'===============================================================================
[+][-]08/12/08 01:53 PM, ID: 22217017

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]08/12/08 02:05 PM, ID: 22217128

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/12/08 02:16 PM, ID: 22217204

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/12/08 02:17 PM, ID: 22217219

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/12/08 02:27 PM, ID: 22217279

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/12/08 02:28 PM, ID: 22217289

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: VB Script, Active Directory, Microsoft Server
Sign Up Now!
Solution Provided By: gregcmcse
Participating Experts: 3
Solution Grade: A
 
 
[+][-]08/12/08 02:35 PM, ID: 22217345

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/12/08 02:39 PM, ID: 22217373

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]08/12/08 02:41 PM, ID: 22217386

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/12/08 04:55 PM, ID: 22218109

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/12/08 05:11 PM, ID: 22218184

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/12/08 05:13 PM, ID: 22218192

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/13/08 09:49 AM, ID: 22223488

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/13/08 02:24 PM, ID: 22225763

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/13/08 04:41 PM, ID: 22226702

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-91 / EE_QW_2_20070628