The below code will search for an entry and loop through the properties in the Active Directory.
//pass in AD server name, account , password that can access to this server
DirectoryEntry entry = newDirectoryEntry(“LDAP://dc1.localserver.localdomain”, “Administrator”, “password”);
DirectorySearcher mySearcher = newDirectorySearcher(entry);
//someone is the user name that you want to search
mySearcher.Filter = “samaccountname=” + “someone”;
SearchResult mySearchResult;
mySearchResult = mySearcher.FindOne();
// Get the properties of the ‘mySearchResult’.
ResultPropertyCollection myResultPropColl;
myResultPropColl = mySearchResult.Properties;
foreach( string myKey in myResultPropColl.PropertyNames)
{
string tab = “ “;
Console.WriteLine(myKey + ” = “);
foreach( Object myCollection in myResultPropColl[myKey])
{
Console.WriteLine(tab + myCollection);
}
}
You can also download a single solution from
http://skydrive.live.com
. The sample file name is ComAppAD.rar. My MSN ID is chanmmn@hotmail.com.
Pingback: Retrieve a specific property from Active Directory | Chanmingman's Blog