.net 查询已禁用帐户的ADAM/ADLDS

.net 查询已禁用帐户的ADAM/ADLDS,.net,active-directory,.net,Active Directory,我正在尝试使用.Net中的DirectorySearcher来查询禁用的用户 我正在使用一个相当快的列表函数,非常类似于这里发布的函数。 我已尝试将过滤器更改为 (&(objectCategory=person)(userAccountControl:1.2.840.113556.1.4.803:=2)) 我没有结果。看来我不能在这个庄园里使用DirectorySearcher。有人做过这样的事吗。我只需要基本信息,更喜欢轻量级/快速查询。使用.NET 3.5中引入的System.Direct

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

我正在使用一个相当快的列表函数,非常类似于这里发布的函数。

我已尝试将过滤器更改为

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


我没有结果。看来我不能在这个庄园里使用DirectorySearcher。有人做过这样的事吗。我只需要基本信息,更喜欢轻量级/快速查询。

使用.NET 3.5中引入的
System.DirectoryServices.AccountManagement
名称空间,类似的事情变得容易多了

请在此处阅读所有相关内容:

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

// 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
,并以“示例查询”样式定义您要查找的内容:

// 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);
}
//创建一个主要对象表示来描述
//将搜索什么
UserPrincipal用户=新的UserPrincipal(ldsContext);
//定义搜索的属性(可以使用通配符)
user.Enabled=false;
user.Name=“user*”;
//创建用于运行搜索操作的主体搜索器
PrincipalSearcher pS=新PrincipalSearcher();
//为创建的主体对象指定查询筛选器属性
//还可以在PrincipalSearcher构造函数中传递用户主体
pS.QueryFilter=用户;
//运行查询
PrincipalSearchResult结果=pS.FindAll();
Console.WriteLine(“以“用户”名称开头的已禁用帐户:”;
foreach(结果中的主要结果)
{
WriteLine(“名称:{0}”,result.name);
}

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

酷。我仍然被困在这片土地上。您是否立即知道这是否会受到与旧查询相同的帐户限制?1000或1500。@Hal Diggs:请看-它说默认页面大小是256 KB的数据,但可以设置为其他大小。为了回答我自己的评论,PrincipleSearcher确实有1000个限制,但您可以通过使用UserPrincipal作为参数PrincipleSearcher(UserPrincipal)构造PrincipleSearcher来绕过它,这似乎允许1000多个结果。奇怪的是,我从未在MSDN上看到过这样的评论。