.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
名前空間を使ってください!
cool。私はまだLDAPの土地で立ち往生していました。これは古いクエリと同じアカウントの制限に悩まされている場合は手を知っていますか? 1000または1500. – hal9000
@Hal Diggs:[MSDN docs for PrincipalSearcher](http://msdn.microsoft.com/en-us/library/system.directoryservices.accountmanagement.principalsearcher.aspx) - 既定のページサイズは256 KBのデータですが、それ以外のものに設定することができます。 –
私の自身のコメントに答えるためには、ええ** PrincipleSearcherは1000の制限があります**しかし、UserPrincipalをパラメータとして使用してPrincipleSearcherを構成することで回避できます** PrincipleSearcher(UserPrincipal)**、これは1000+結果。私はこれを見たことがない奇妙なMSDNのコメント。 – hal9000