寻找什么组/通讯组列表的特定用户所属的Active Directory中 [英] Finding what Groups/Distribution lists a specific user belongs to in active directory

查看:163
本文介绍了寻找什么组/通讯组列表的特定用户所属的Active Directory中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我在

OU=Groups,DC=contaco,DC=com,ct

我能找到的所有组在子OU,但要找到所有组用户bobdole的唯一途径是属于由我来看看各组,看他是在成员字段。

I can find all the groups in a sub OU, but the only way to find all of the groups user 'bobdole' belongs to is for me to look at each group and see if he is in the 'member' field.

不幸的是,当我看着用户bobdole',我没有看到一个成员字段具有所有这些名单中,所以我必须通过枚举每个组\通讯组列表,看看他是一个成员。

Unfortunately, when I look at user 'bobdole', I don't see a memberOf field that has all of these lists, hence I have to enumerate through each group\distribution list and see which he is a member of.

有没有更有效的方法来做到这一点?我在C#

Is there no more efficient way to do this? I'm in c#

推荐答案

这将返回所有角色,用户所属(组)。

This returns all the roles (Groups) that a user belongs to.

public string[] GetRolesForUser(DirectoryEntry user)
{       
    user.RefreshCache(new string[] { "tokenGroups" });

    var irc = new IdentityReferenceCollection(user.Properties["tokenGroups"].Count);
    foreach (byte[] sidBytes in user.Properties["tokenGroups"])
    	irc.Add(new SecurityIdentifier(sidBytes, 0));

    var coll = new StringCollection();
    irc = irc.Translate(typeof(NTAccount));

    foreach (var ir in irc)
    {
    	if (ir is NTAccount)
    	{
    		coll.Add(ir.ToString());
    	}
    }
    var accounts = new string[coll.Count];

    coll.CopyTo(accounts, 0);
    return accounts;
}

这篇关于寻找什么组/通讯组列表的特定用户所属的Active Directory中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆