Users in an OU versus users in a Group

Posted on 2006-05-24
Medium Priority
Last Modified: 2010-04-30
From the code like this:

Set objCon = CreateObject("ADODB.Connection")
objCon.Open "Provider=ADsDSOObject;"
Set objCmd = CreateObject("ADODB.Command")
Set objCmd.ActiveConnection = objCon

objCmd.CommandText = "<LDAP://>;(&(objectCategory=Group)(cn=Group1));distinguishedname,name,member;range=0-9;subtree"

Set objRS = objCmd.Execute

Do While (Not objRS.EOF)
  WScript.Echo objRS("distinguishedname")
  WScript.Echo objRS("name")
  WScript.Echo Join(objRS("member;range=0-9"), vbCrLf)

I can now get all the users in a Group (with a range) ......... however, if I try to get all the users in an OU (with a range) (which I know the code above might change a little) I am having trouble with the objCmd.CommandText line ..... if the OU=NeedVacation, how could I modify the query to work for the OU?
Question by:249Central
  • 2
  • 2
LVL 14

Expert Comment

ID: 16754708
The range code only applies to selecting multi-valued attributes of objects in an ADO search.  It does not apply to OUs, since users are not "attributes" of an OU the way a member list is.

Why do you need to select a specific "range" of users from an OU?  I don't quite understand where this question is coming from, but I can probably help you with the solution once I see what it is you really need to accomplish.

Author Comment

ID: 16755080
The problem is that this particular OU has 2000+ users its not returning all of them.
LVL 14

Accepted Solution

dlwyatt82 earned 2000 total points
ID: 16755137
Ah, I've run into that before as well.  To resolve this particular problem, you need to perform a "paged search".  Luckily, most of that is performed behind the scenes by ADO, and you script needs only one modification:  before you call objCon.Execute, do this:

objCon.Properties("Page Size") = 1000

Even though you set the "Page Size" property to 1000, your script will obtain all of the users in the group for your RecordSet.  The paging is performed by ADO (it retrieves 1000 results at a time from the Domain Controller, as many times as are needed to get the complete list).

Author Comment

ID: 16755212
I was a little lost ... thanks.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month15 days, 15 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question