LDAP怎样获取AD域中指定组的所有用户
1个回答
2017-09-08 · 知道合伙人互联网行家
正青春梦飞扬
知道合伙人互联网行家
向TA提问 私信TA
知道合伙人互联网行家
采纳数:6837
获赞数:306021
对SEO有这独特见解 工作努力积极、团结同事 连续2个月个人工作完成优秀 客户0投诉 评委最佳班组经理
向TA提问 私信TA
关注
展开全部
public DataSet GetUsersForGroup(string GroupName) { //if (GroupName.IndexOf(';') > 0) //{ // return GetUsersForGroup(GroupName.Split(new char[] { ';' })); //} if (GroupName == string.Empty) return null; try { DirectoryEntry dir = GetDirectoryObject(); dir.RefreshCache(); DirectorySearcher ds = new DirectorySearcher(dir); ds.Filter = "(&(objectClass=group)(cn=" + GroupName + "))"; ds.PropertiesToLoad.Add("memberof"); SearchResult results = ds.FindOne(); DataSet dsUser = new DataSet(); DataTable tbUser = dsUser.Tables.Add("Users"); tbUser.Columns.Add("GroupName"); tbUser.Columns.Add("samaccountname"); tbUser.Columns.Add("UserName"); tbUser.Columns.Add("DisplayName"); tbUser.Columns.Add("EMailAddress"); tbUser.Columns.Add("primaryGroupID"); if (results != null) { DirectoryEntry deGroup = new DirectoryEntry(results.Path, _ADUser, _ADPwd, AuthenticationTypes.Secure); System.DirectoryServices.PropertyCollection pcoll = deGroup.Properties; int n = pcoll["member"].Count; for (int i = 0; i < n; i++) { DirectoryEntry deUser = new DirectoryEntry(_ADPath + "/" + pcoll["member"][i].ToString(), _ADUser, _ADPwd, AuthenticationTypes.Secure); try { DataRow rwUser = tbUser.NewRow(); rwUser["GroupName"] = GroupName; rwUser["samaccountname"] = GetProperty(deUser, "samaccountname"); rwUser["UserName"] = GetProperty(deUser, "cn"); rwUser["DisplayName"] = GetProperty(deUser, "givenName") + " " + GetProperty(deUser, "sn"); rwUser["EMailAddress"] = GetProperty(deUser, "mail"); rwUser["primaryGroupID"] = GetProperty(deUser, "primaryGroupID"); tbUser.Rows.Add(rwUser); deUser.Close();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询