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

后端 未结 2 465
旧时难觅i
旧时难觅i 2020-12-21 10:24

I have a question about determining the type (User or Group) of a account name.
For example, I have two strings, say \"Adventure-works\\david\" and \"Adventure-works\\ad

2条回答
  •  忘掉有多难
    2020-12-21 10:51

    Warning: In case of using DirectorySearcher the accepted answer might fail, since objectCategory it doesn't return consistent results.

    Consider using objectClass instead:

    SearchResult sr = ds.FindOne();
    bool isUser = sr.Properties["objectClass"]?.Contains("user") == true;
    // OR
    bool isGroup = sr.Properties["objectClass"]?.Contains("group") == true;
    

提交回复
热议问题