I found How can I get a list of users from active directory?
It is helpful when I only have a few users, but I have so many users in AD, so when I run my query
if ((String)(entry.Properties["sn"].Value) == "lname"
&& (String)(entry.Properties["givenName"].Value) == "fname")
{
return entry.Properties["samAccountName"].Value.ToString();
}
it took too long to finish.
What can I do to search one particular user logon id by first name and last name?
Since you’re on .NET 4, you should check out the
System.DirectoryServices.AccountManagement(S.DS.AM) namespace. Read all about it here:Basically, you can define a domain context and easily find users and/or groups in AD:
If you cannot find a user specified by a user name, you can also use the new search functionality:
The new S.DS.AM makes it really easy to play around with users and groups in AD! And just finding a single user should be relatively quick, too.