查询从Active Directory用户的组成员资格 [英] Querying a user's group membership from Active Directory

查看:139
本文介绍了查询从Active Directory用户的组成员资格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一个快速的方法来查询信息从Active Directory。

I wanted to know if there's a fast way to query information from Active Directory.

具体而言,我想查询它与给定的字符串开始组当前用户的成员,说ABC-为例。

Specifically, I'm trying to query the current user's "member of" groups which starts with a given string, say "abc-" for example.

如果任何人能帮助我,我真的很AP preciate吧。

If any one can help me I would really appreciate it.

推荐答案

您可以做到以不同的方式,的管理目录安全主体在.NET Framework 3.5 可以帮助你这样的:

You can do it in different ways, Managing Directory Security Principals in the .NET Framework 3.5 helps you this way:

static void Main(string[] args)
{
  /* Retreiving a principal context
   */
  PrincipalContext domainContext = new PrincipalContext(ContextType.Domain, "WM2008R2ENT", "dc=dom,dc=fr", "TheUser", "ThePassword");

  /* Discribe the group You are looking for as a principal
   */
  GroupPrincipal gpPrincipal = new GroupPrincipal(domainContext);
  gpPrincipal.Name = "abc-*";

  /* Bind a searcher
   */
  PrincipalSearcher searcher = new PrincipalSearcher();
  searcher.QueryFilter = gpPrincipal;

  PrincipalSearchResult<Principal> hRes = searcher.FindAll();

  /* Read The result
   */
  foreach (GroupPrincipal grp in hRes)
  {
    Console.WriteLine(grp.Name);
    // You are looking for "grp.Members"
  }

  Console.ReadLine();
}

我希望它能帮助。

I hope it helps.

这篇关于查询从Active Directory用户的组成员资格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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