以下のコードを考えると
using (var context = new PrincipalContext(ContextType.Domain, SOME_DOMAIN))
using (UserPrincipal userPrincipal = new UserPrincipal(context) { Enabled = true })
using (PrincipalSearchResult<Principal> results = new PrincipalSearcher(userPrincipal).FindAll())
{
Console.WriteLine(results.Count());
}
using (var context = new PrincipalContext(ContextType.Domain, SOME_DOMAIN))
using (CustomUserPrinciple userPrincipal = new CustomUserPrinciple(context) { Enabled = true })
using (PrincipalSearchResult<Principal> results = new PrincipalSearcher(userPrincipal).FindAll())
{
Console.WriteLine(results.Count());
}
[DirectoryObjectClass("user")]
[DirectoryRdnPrefix("CN")]
public class CustomUserPrinciple : UserPrincipal
{
public CustomUserPrinciple(PrincipalContext context)
: base(context)
{
}
}
カウントは同じだと思っていましたが、カスタムプリンシパルを使用した検索では、最初の検索のようにユーザーだけが返されるわけではないようです。結果には、コンピューターなどの他のActiveDirectoryオブジェクトタイプが含まれます。
これは仕様によるものですか?そうであれば、カスタムプリンシパル検索を制限してユーザーのみを返す方法はありますか?