Solved

Enumerating the objects in an OU

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

Industry Leaders: 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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

756 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