Retrieving custom Active Directory properties of users

后端 未结 2 1012
孤城傲影
孤城傲影 2020-12-21 19:25

I\'ve been trying to retrieve two custom properties that are set on our Active Directory users, but it seems like I keep getting a constant list of Properties (tested over 2

2条回答
  •  春和景丽
    2020-12-21 19:44

    Though not a direct answer to your question, following is what we use:

            public static string GetProperty(string adUserId, string domain, string lDAPLoginId, string lDAPPassword, string propertyName)
            {
                PrincipalContext ctx = new PrincipalContext(ContextType.Domain, domain, lDAPLoginId, lDAPPassword);
                UserPrincipal up = UserPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, adUserId);
    
                string result = "";
    
                if (up != null)
                {
                    result = PrincipalGetProperty(up, propertyName);
                }
    
                return result;
            }
    

提交回复
热议问题