c# - 在 C# 中排除 Active Directory 的 PrincipalSearcher QueryFilter 中的空结果

标签 c# active-directory

尝试在 Active Directory 中搜索有关用户的非空描述(意味着他们有职位),如下面第 4 行所示,但出现无法使用排除项的错误!

关于另一种方法的建议?

PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
UserPrincipal qbeUser = new UserPrincipal(ctx);
PrincipalSearcher srch = new PrincipalSearcher(qbeUser);
var example = new UserPrincipal(ctx) { Description != null };

最佳答案

我会尝试这样的事情:

using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain))
{
    UserPrincipal qbeUser = new UserPrincipal(ctx);
    qbeUser.Description = "*";   // something, anything - just not empty/NULL

    PrincipalSearcher srch = new PrincipalSearcher(qbeUser);
     ......
}

这对你有用吗?基本上,只需在 qbeUser 上定义属性并使用 * 作为通配符表示您希望用户在 Description 属性中有一些东西 - 一些东西, 任何东西 - 不是什么都没有。

关于c# - 在 C# 中排除 Active Directory 的 PrincipalSearcher QueryFilter 中的空结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14095832/

相关文章:

powershell - Powershell尝试将用户从一个AD组复制到另一个AD组

c++ - 验证 native 的 Active Directory 域信任关系

azure - 有没有办法返回 Microsoft Graph API 中给定对象 ID 的用户的身份验证手机号码?

c# - 从 C# 将数据导出到 PDF 时出错

c# - 直接将文件上传到azure?

c# - 如何在返回的 LINQ 中从 db 表中排除两列?

powershell - MSA 操作日志在哪里?

c# - 在具有相同属性的 XML 元素之间导航

c# - WPF MVVM 设计问题

c# - 为什么我的 LDAP 查询失败?