How to know which email address already disabled by LDAP
-
Tuesday, August 23, 2005 7:27 AM
I using LDAP to connect exchange server that I has success to retrieve email address from exchange server but I don't know which property can tell me the account is disabled or not.
The following is the sample code
string ldapQuery = "LDAP://IPAddress/DC=domain,DC=com";
System.DirectoryServices.DirectoryEntry entry = new System.DirectoryServices.DirectoryEntry(ldapQuery, "username", "password");
System.DirectoryServices.DirectorySearcher searcher = new System.DirectoryServices.DirectorySearcher();
searcher.SearchRoot = entry;
searcher.SearchScope = System.DirectoryServices.SearchScope.Subtree;searcher.Filter = @"(& (mailnickname=*) (| (&(objectCategory=person)(objectClass=user)(!(homeMDB=*))(!(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=user)(|(homeMDB=*)(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=contact))(objectCategory=group)(objectCategory=publicFolder) ))";
System.DirectoryServices.SearchResultCollection results = searcher.FindAll();
foreach(System.DirectoryServices.SearchResult result in results)
{
try
{
ActiveDs.IADsUser userAccount = (ActiveDs.IADsUser) result.GetDirectoryEntry().NativeObject;
Debug.Write(userAccount.AccountDisabled);
}
catch(System.InvalidCastException)
{
}
try
{
System.DirectoryServices.ResultPropertyValueCollection mails = result.Properties["mail"];
}
catch(System.NullReferenceException)
{
}
}
Any suggestion?
Thank you

