2016-10-06 11 views
1

アクティブなディレクトリオブジェクトを検出する正しい方法は、グループまたはユーザーに属していますか?ここで私はC#で処理する方法である:アクティブなディレクトリオブジェクトを検出する正しい方法は、ユーザーまたはグループに属していますか?

より作成
foreach (SearchResult sr in src) 
{ 
    if (sr.Properties["objectclass"].Contains("person") && sr.Properties["objectclass"].Contains("user")) 
    { 
     // USER ? 
    } 
    if (sr.Properties["objectclass"].Contains("group")) 
    { 
     // GROUP ? 
    } 
} 
+1

あなたの方法は、(それがないのobjectClass?)良いことができます。 OUのCNは、次のとおりです。objectClassの\tのorganizationalUnit 人のCNさ:オブジェクトクラス\t人 グループたちのCN:オブジェクトクラス\tグループ 他の方法は、あなたが取得する場合、そのような方法で広告を整理することができDirectoryEntryのパス、それはグループまたはユーザーであることがわかっている –

答えて

2
if (sr != null) 
{ 
    if(sr.Properties["objectCategory"] != null) 
    { 
     // objectType will be "Person" or "Group" (or something else entirely) 
     string objectType = sr.Properties["objectCategory"][0].ToString(); 
     if (objectType == "Person") 
     { 
      //It's a user 
     } 
     if (objectType == "Group") 
     { 
      //It's a Group 
     } 
    } 
} 

How to determine the type (AD User vs. AD Group) of an account?

+0

オブジェクトが削除されたときにobjectCategory属性が削除されるため、削除されたオブジェクトのオブジェクトタイプを実際に判別したかったのです。私は新しい質問[質問のリンク](http://stackoverflow.com/questions/39910792/how-to-determine-typeuser-or-group-of-a-deleted-active-directory-object-using) –

関連する問題