Loop through all AD properties

M

Martin

Hi,

Can anybody please tell me (or point me to documentation on) how to loop
through all AD properties of a user.
The code I have so far is below.
Now if I know the property name I can retrieve it, for eample to retrieve
"DisplayName"
I would just say.

de.Properties["DisplayName"].Value

so what I would like is just a display of all properties for a user,
something like this

DisplayName
Mail
Title
sAMAccountName
GivenName


it would also be nice to know what type a particular object is, for example
most properties are strings however I believe some properties are "C stucts"
cause they contain more than a single string although just to start I'd be
happy just to get the property names.

any help is appreciated

cheers

martin.

using System;
using System.DirectoryServices;

namespace TestConsole
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
string query;
//query =
ConfigurationSettings.AppSettings.Get("ActiveDirectoryQueryString");
query = "LDAP://mydomain";
System.DirectoryServices.DirectoryEntry entry = new
System.DirectoryServices.DirectoryEntry(query);
System.DirectoryServices.DirectorySearcher mySearcher = new
System.DirectoryServices.DirectorySearcher(entry);

try
{
foreach(System.DirectoryServices.SearchResult resEnt in
mySearcher.FindAll())
{
System.DirectoryServices.DirectoryEntry de=resEnt.GetDirectoryEntry();

//would like to get all properties (property name) here perhaps in a
foreach loop
foreach (DirectoryEntry child in de.Children)
{
Console.WriteLine(child.Name);
}

}

}
catch (Exception ex)
{
Console.WriteLine("ERROR ERROR ERROR " + ex.Message);
}
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top