using System.DirectoryServices.AccountManagement;
public static void Main(string[] args)
GetADUserName("intranet.nav.gov.hu", args[0], args[1]);
Console.WriteLine(ex.Message);
private static string UserDisplayName
public static string GetADUserName(string adPath, string userName, string nameType)
using (PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, adPath))
UserPrincipal user = UserPrincipal.FindByIdentity(principalContext, userName);
UserDisplayName = user.DisplayName.ToString();
UserDisplayName = user.UserPrincipalName.ToString();
UserDisplayName = "Invalid AD user name";
principalContext.Dispose();
Console.WriteLine(ex.Message);