Solved

Enumerating the objects in an OU

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

734 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