首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >查询ADAM/ADLDS中禁用的帐户

查询ADAM/ADLDS中禁用的帐户
EN

Stack Overflow用户
提问于 2011-02-04 04:38:17
回答 1查看 2K关注 0票数 2

我正在尝试使用.Net中的DirectorySearcher来查询禁用用户。

我使用了一个非常快的列表函数,与这里发布的函数非常相似。Enumerating Large Groups With Active Directory

我已尝试将过滤器更改为

(&(objectCategory=person)(userAccountControl:1.2.840.113556.1.4.803:=2))

我没有得到任何结果。似乎我不能在这个庄园里使用DirectorySearcher。有没有人做过这样的事。我只需要基本的信息,并喜欢一个轻量级/快速的查询。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-02-04 05:32:58

使用.NET 3.5中引入的System.DirectoryServices.AccountManagement命名空间,这样的事情变得容易得多。

点击此处阅读所有相关信息:Managing Directory Security Principals in the .NET Framework 3.5

您首先必须为您的操作建立一个上下文-明确支持AD LDS:

代码语言:javascript
复制
// create a context for an AD LDS store pointing to the 
// partition root using the credentials for a user in the AD LDS store 
// and SSL for encryption
PrincipalContext ldsContext = new PrincipalContext(
    ContextType.ApplicationDirectory, "sea-dc-02.fabrikam.com:50001", 
    "ou=ADAM Users,o=microsoft,c=us", 
    ContextOptions.SecureSocketLayer | ContextOptions.SimpleBind, 
    "CN=administrator,OU=ADAM Users,O=Microsoft,C=US ", "pass@1w0rd01");

然后,您将创建一个PrincipalSearcher,并以“按示例查询”的方式定义您要查找的内容:

代码语言:javascript
复制
// create a principal object representation to describe
// what will be searched 
UserPrincipal user = new UserPrincipal(ldsContext);

// define the properties of the search (this can use wildcards)
user.Enabled = false;
user.Name = "user*";

// create a principal searcher for running a search operation
PrincipalSearcher pS = new PrincipalSearcher();

// assign the query filter property for the principal object you created
// you can also pass the user principal in the PrincipalSearcher constructor
pS.QueryFilter = user;

// run the query
PrincipalSearchResult<Principal> results = pS.FindAll();

Console.WriteLine("Disabled accounts starting with a name of 'user':");
foreach (Principal result in results)
{
    Console.WriteLine("name: {0}", result.Name);
}

很漂亮,是吧?如果可以的话,请使用新的S.DS.AM命名空间!

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4891442

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档