Solved

Enumerating the objects in an OU

Posted on 2004-09-28
4
877 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
[X]
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
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

724 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