2011-02-03 12 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名前空間を使用すると、それほど簡単になります。

// 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を作成し、定義したい: - AD LDSが明示的にサポートされてManaging Directory Security Principals in the .NET Framework 3.5

あなたが最初にあなたの操作のためのコンテキストを確立する必要があります。ここにそれについてのすべてを読む

「例による問合せ」スタイルで、あなたが探しているもの:

// 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) - 既定のページサイズは256 KBのデータですが、それ以外のものに設定することができます。 –

+1

私の自身のコメントに答えるためには、ええ** PrincipleSearcherは1000の制限があります**しかし、UserPrincipalをパラメータとして使用してPrincipleSearcherを構成することで回避できます** PrincipleSearcher(UserPrincipal)**、これは1000+結果。私はこれを見たことがない奇妙なMSDNのコメント。 – hal9000

関連する問題