• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2295
  • Last Modified:

How do I find user group information from LDAP using c#

I'm really new to LDAP and I have to learn how to get the user group information using c#.  My inputs are:

IP address of the LDAP server
domain name

And then I have to return the group user info.

Yikes.  Help me please.   I only had 80 points left to ask this question.  I am sorry.
1 Solution
Chris DentPowerShell DeveloperCommented:

Hey :)

Something like this?

using System.DirectoryServices;
namespace ConsoleApplication1
    class Program
        static void Main(string[] args)
            String ipAddress = "";
            String ldapFilter = "(sAMAccountName=TheUsername)";
            DirectoryEntry adDomain = new DirectoryEntry("LDAP://" + ipAddress);
            DirectorySearcher adSearch = new DirectorySearcher(adDomain, ldapFilter);
            adSearch.PropertiesToLoad.AddRange(new String[] {"name", "memberOf"} );
            SearchResult adResult = adSearch.FindOne();
            Console.WriteLine(adResult.Properties["name"][0].ToString() + " is a member of:");
            foreach (Object adGroup in adResult.Properties["memberof"])

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now