Solved

Enumerating the objects in an OU

Posted on 2004-09-28
4
870 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now