[英]Check list of users exist in Active Directory using LDAP in C#
I need to pass a list of user's SamAcountName / UserPrincipalName and check if those users do exist in Active Directory.我需要传递用户的 SamAcountName / UserPrincipalName 列表并检查这些用户是否存在于 Active Directory 中。
I know that we can check only one item whether it exist or not using following method.我知道我们只能使用以下方法检查一项是否存在。 But I need to pass a whole list of SamAcountName / UserPrincipalName and check whether users exist.但我需要传递 SamAcountName / UserPrincipalName 的完整列表并检查用户是否存在。
public bool UserExist(string samAccountName)
{
try
{
using (var domainContext = GetPrincipalContext())
{
using (var foundUser = UserPrincipal.FindByIdentity(domainContext, IdentityType.SamAccountName, samAccountName))
{
return foundUser != null;
}
}
}
catch (Exception e)
{
_logger.LogWarning($"{nameof(CheckUserExistBySAM)}: Exception: {e}");
return false;
}
}
Try use something like:尝试使用类似的东西:
UserPrincipal u = new UserPrincipal(domainContext);
PrincipalSearcher search = new PrincipalSearcher(u);
var usersInYourAD = search.FindAll(); //merge this with your list of users etc.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.