user2621781
user2621781

Reputation: 11

DirectoryEntry Properties

I have a short quest for my C# project. I want to read out our active directory and use this:

System.DirectoryServices.DirectorySearcher mySearcher = new System.DirectoryServices.DirectorySearcher(entry);

foreach (System.DirectoryServices.SearchResult resEnt in mySearcher.FindAll())
{
        System.DirectoryServices.DirectoryEntry de = resEnt.GetDirectoryEntry();
        try
        {
            myRow["eMail"] = de.Properties["Mail"].Value.ToString();
        }
        catch (Exception)
        { }
}

Now I want to read out other Properties and hope that you can give me a List of all Properties.

Thanks

Upvotes: 0

Views: 23453

Answers (1)

Kevin M
Kevin M

Reputation: 5506

You can do it simply by below code

 DirectorySearcher mySearcher = new System.DirectoryServices.DirectorySearcher(entry);

            foreach (System.DirectoryServices.SearchResult resEnt in mySearcher.FindAll())
            {
                try
                {
                    foreach (string property in resEnt.Properties.PropertyNames)
                    {
                        string value = resEnt.Properties[property][0].ToString();

                        Console.WriteLine(property + ":" + value);
                    }
                }
                catch (Exception)
                { }
            }

Upvotes: 8

Related Questions