• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
KXLF’s blog
能转的不写
   首页    新随笔    联系   管理     

取得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;
posted @ 2009-05-23 14:42  KXLF  阅读(680)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3