Re: How to tally group membership for huge group +10k accounts?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Sport wrote:

Need a count of users/computers in a group membership that is upwards
of 13-15k accounts.

ADSI is no go and stops at 1500
ADO putters out at 6110
csvde dies at 1500 as well
ldifde gets a bit more, at least 10k, but the format is terrible.

Don't really need a long list would be happy with just a echo of the
number of accounts in group.


To document groups with more than 1500 members you have to use ADO range
limits to retrieve all values of the member attribute of the group. I have a
sample VBScript that uses this technique to document large groups linked
here:

http://www.rlmueller.net/DocumentLargeGroup.htm

However, you can also query for all objects that have the group DN in the
memberOf attribute. Instead of one row with thousands of values, you get a
recordset with thousands of rows. You just need to use paging if you
enumerate the recordset, but if all you need is the count you can use the
RecordCount property. In brief:
===========
' Specify Distinguished Name of the large group.
strGroupDN = "cn=Big Group,ou=Sales,dc=MyDomain,dc=com"

' Use ADO to search the domain for members of the group.
Set adoConnection = CreateObject("ADODB.Connection")
Set adoCommand = CreateObject("ADODB.Command")
adoConnection.Provider = "ADsDSOOBject"
adoConnection.Open "Active Directory Provider"
Set adoCommand.ActiveConnection = adoConnection

' Determine the DNS domain from the RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE";)
strDNSDomain = objRootDSE.Get("defaultNamingContext")

' Filter on all objects that are members of the group.
strFilter = "(memberOf=" & strGroupDN & ")"

' Construct the LDAP syntax query.
strQuery = "<LDAP://"; & strDNSDomain & ">;" & strFilter _
& ";distinguishedName;subtree"

' Run the query.
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
Set adoRecordset = adoCommand.Execute

' Retrieve number of records.
strNumber = adoRecordset.RecordCount
Wscript.Echo "Number of members: " & strNumber

' Clean up.
adoRecordset.Close
adoConnection.Close
============
Or, you could enumerate the recordset with:

' Enumerate all members.
Set adoRecordset = adoCommand.Execute
Do Until adoRecordset.EOF
strDN = adoRecordset.Fields("distinguishedName").Value
Wscript.Echo strDN
adoRecordset.MoveNext
Loop

But if you do both (enumerate and retrieve the count), you must use:

adoRecordset.CursorType = 3

and after retrieving the count use:

adoRecordset.MoveFirst

before the loop to enumerate the recordset. However, I suspect you just want
the count.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--


.



Relevant Pages

  • Re: How to tally group membership for huge group +10k accounts?
    ... The first thing I did was run your ADO Large Group and it stops at ... recordset with thousands of rows. ... ' Use ADO to search the domain for members of the group. ... you could enumerate the recordset with: ...
    (microsoft.public.windows.server.scripting)
  • Re: How to tally group membership for huge group +10k accounts?
    ... Let me know if the code to retrieve RecordCount works. ... recordset with thousands of rows. ... ' Use ADO to search the domain for members of the group. ... you could enumerate the recordset with: ...
    (microsoft.public.windows.server.scripting)
  • Re: Is ADO Dead (3)?
    ... The Design of ADO ... ADO uses a single object, the Recordset, as a common representation for ... a forward-only stream of results from a database, ... where data is updated at the data source or cached locally as with the ...
    (comp.databases.ms-access)
  • Re: Is ADO Dead (3)?
    ... The Design of ADO ... ADO uses a single object, the Recordset, as a common representation for ... a forward-only stream of results from a database, ... where data is updated at the data source or cached locally as with the ...
    (comp.databases.ms-access)
  • Re: Is ADO Dead (3)?
    ... The Design of ADO ... ADO uses a single object, the Recordset, as a common representation for ... a forward-only stream of results from a database, ... where data is updated at the data source or cached locally as with the ...
    (comp.databases.ms-access)