zoukankan      html  css  js  c++  java
  • 取得AD中某个组织下所有用户的登录名

        string strLDAP = ConfigurationSettings.AppSettings["LDAP"];
         
    string strUserName = ConfigurationSettings.AppSettings["userName"];
         
    string strUserPwd = ConfigurationSettings.AppSettings["userPwd"];

         DirectoryEntry entry 
    = new DirectoryEntry(strLDAP, strUserName, strUserPwd);
         DirectorySearcher mySearcher 
    = new DirectorySearcher(entry);
         mySearcher.PageSize 
    = 99999;  // 默认为1000,此处要注意,可能会造成取用户不全。
         mySearcher.Filter = ("(objectClass=user)"); //user表示用户,group表示组

         SearchResultCollection userCollection 
    = mySearcher.FindAll();
         
    string[] users = new string[userCollection.Count];

         
    for (int i = 0; i < userCollection.Count; i++)
         {
               DirectoryEntry oneUser 
    = new DirectoryEntry(userCollection[i].Path);
               
    if (oneUser.Properties.Contains("userPrincipalName"))
               {
                   users[i
    = oneUser.Properties["userPrincipalName"].Value.ToString();
               }
               
    else
               {
                   users[i
    = "NULL";
               }
         }

         
    return users;
  • 相关阅读:
    noi.ac #30 思维
    bzoj 2330: [SCOI2011]糖果
    bzoj 2326: [HNOI2011]数学作业
    bzoj 2324: [ZJOI2011]营救皮卡丘
    bzoj 2301: [HAOI2011]Problem b
    bzoj 2286: [Sdoi2011消耗战
    bzoj 2282: [Sdoi2011]消防
    bzoj 2257: [Jsoi2009]瓶子和燃料
    bzoj 2245: [SDOI2011]工作安排
    bzoj 2244: [SDOI2011]拦截导弹
  • 原文地址:https://www.cnblogs.com/kxlf/p/1487658.html
Copyright © 2011-2022 走看看