本帖最后由 liangchengfck1 于 2012-11-12 10:37:25 编辑

解决方案 »

  1.   

    ok
    public partial class adgroup : System.Web.UI.Page    {        string LDAP = "LDAP://";        string groupName = "USB 15DRW";        protected void Page_Load(object sender, EventArgs e)        {            if (!IsPostBack)            {                StringCollection groupMembers = this.GetGroupMembers(groupName);                foreach (var user in groupMembers)                {                    Response.Write(user.ToString() + "<br/>");                }            }        }         public StringCollection GetGroupMembers(string strGroup)        {            StringCollection groupMemebers = new StringCollection();            try            {                DirectoryEntry ent = new DirectoryEntry(LDAP);                DirectorySearcher srch = new DirectorySearcher("(CN=" + strGroup + ")");                SearchResultCollection coll = srch.FindAll();                foreach (SearchResult rs in coll)                {                    ResultPropertyCollection resultPropColl = rs.Properties;                    foreach (Object memberColl in resultPropColl["member"])                    {                        DirectoryEntry gpMemberEntry = new DirectoryEntry("LDAP://" + memberColl);                        System.DirectoryServices.PropertyCollection userProps = gpMemberEntry.Properties;                        object obVal = userProps["sAMAccountName"].Value;                        if (null != obVal)                        {                            groupMemebers.Add(obVal.ToString());                        }                    }                }            }            catch (Exception ex)            {                throw;            }            return groupMemebers;        }    }
      

  2.   

     string LDAP = "LDAP://……"; 
      

  3.   

    linq 实现
    var list=new list<oMembers>();
    foreach (UserPrincipalExtentsion oUser in oUsersFromAD)   //AD里所有的用户
                {
                   list.Add(oMembers.Where(o=>o. UserPrincipalName== oUser.UserPrincipalName ));
          }
      }
      

  4.   

    或者
    DirectoryEntry de = new DirectoryEntry("LDAP://" + "域名", "用户名", "密码", AuthenticationTypes.Secure);  
          
    DirectorySearcher ds = new DirectorySearcher();         
    ds.SearchRoot = de;    
    ds.Filter = ("(objectClass=user)"); group是组
          
    foreach (SearchResult result in ds.FindAll())         
    {         
                string name = result.GetDirectoryEntry().Name.ToString();
         
                Page.Response.Write(name);