Find user in Active Directory
Find User in Active Directory
Add References to
System.DirectoryServices;
System.DirectoryServices.AccountManagement;
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;
public string GetAdUser(string userName)
{
using (PrincipalContext context = new PrincipalContext(ContextType.Domain))
{
string controller = context.ConnectedServer;
UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(context, userName);
return userPrincipal.UserPrincipalName;
}
}