Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Enumerating the objects in an OU

Posted on 2004-09-28
4
874 Views
Last Modified: 2012-06-27
Hello,

I want to get an enumerating of the objects in an OU using C#.
Especially the user objects of an OU.

I've got no Problem to enumerate user of an group using (COM) Interop.ActiveDs (Active DS Type Library).
For instance :

[Code]      
      StringCollection scGroupMembers = new StringCollection();
      string strLDAPGroup = "LDAP://server1/CN=Group1,CN=Users,DC=domaindc1,DC=domaindc2,DC=domaindc3";
      DirectoryEntry deGroup = new DirectoryEntry(strLDAPGroup);

      try
      {

            IADsMembers adsiMembers = (IADsMembers)deGroup.Invoke("Members");
            adsiMembers.Filter = new object[] {"user"};
            foreach (IADsUser adsiUser in adsiMembers)
            {
                        scGroupMembers.Add(adsiUser.ADsPath);
            }

      }

      finally
      {
            deGroup.Dispose();
      }

      return(scGroupMembers);
[/Code]      

But how is it possible to get all childs of an OU?
Do I have to use IADsCollection?

Maybe there is another way than using Interop.ActiveDs?

I would be very glad for any advice.
Thank you.

Best regards.
develc
0
Comment
Question by:develc
4 Comments
 
LVL 20

Accepted Solution

by:
ihenry earned 500 total points
ID: 12170193

In .NET Framework the best practice is to use DirectoryServices API. Given an OU, you can enumerate child objects like users, groups, or any object type. Look at these articles

Enumerating Child Objects
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sds/sds/enumerating_child_objects.asp

Enumerating Users and Groups
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sds/sds/enumerating_child_objects.asp
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

860 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