检测活动目录对象的正确方法是什么属于组或用户?这是我在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 ?
}
}
答案 0 :(得分: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?