2011-02-03 3 views
2

.Net에서 DirectorySearcher를 사용하여 비활성화 된 사용자를 쿼리하려고합니다.비활성화 된 계정에 대한 ADAM/ADLDS 쿼리

여기에 게시 된 것과 매우 유사한 매우 빠른 목록 기능을 사용하고 있습니다. Enumerating Large Groups With Active Directory.

나는

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

내가 어떤 결과를 얻을에 필터를 변경 시도했다. 이 저택에서 DirectorySearcher를 사용할 수없는 것 같습니다. 아무도 이런 짓을하지 않았습니까? 난 그냥 기본 정보가 필요하고 가볍거나 빠른 쿼리를 선호합니다.

답변

3

. NET 3.5에 도입 된 System.DirectoryServices.AccountManagement 네임 스페이스를 사용하면 훨씬 쉽게 될 수 있습니다. AD LDS가 명시 적으로 지원됩니다 - Managing Directory Security Principals in the .NET Framework 3.5

먼저 당신의 작업에 대한 컨텍스트를 설정해야합니다 :

// 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 ", "[email protected]"); 

을 다음 당신은 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); 
} 

꽤 멋진, 어? 새로운 S.DS.AM 네임 스페이스를 사용할 수 있다면!

+0

cool. 나는 아직 LDAP 토지에 머물러 있었다. 이전 검색어와 동일한 계정 제한으로 인해 어려움을 겪고 있다면 손을 안다는 사실을 알고 있습니까? 1000 또는 1500입니다. – hal9000

+0

@Hal Diggs : [MSDN docs for PrincipalSearcher] (http://msdn.microsoft.com/en-us/library/system.directoryservices.accountmanagement.principalsearcher.aspx) - 기본 페이지 크기는 256KB의 데이터이지만 다른 것으로 설정 될 수 있습니다. –

+1

내 대답에 대답, 예 ** PrincipleSearcher는 1000 한계가 **하지만 UserPrincipal을 매개 변수로 사용하여 PrincipleSearcher를 구성하면 해결할 수 있습니다 ** PrincipleSearcher (UserPrincipal) **, 1000+ 결과. 이상하게도 MSDN에 대한이 주석은 본 적이 없습니다. – hal9000

관련 문제