热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

AD学习--如何获得域中的用户

代码出自http:www.c-sharpcorner.comCode2003AprilListingADUsers.aspConsole.Write(EnteryourDomai

代码出自http://www.c-sharpcorner.com//Code/2003/April/ListingADUsers.asp

Console.Write("Enter your Domain Name : ");
   string dom =Console.ReadLine();

   System.DirectoryServices.DirectoryEntry entry = new System.DirectoryServices.DirectoryEntry("LDAP://" + dom);
   System.DirectoryServices.DirectorySearcher mySearcher = new System.DirectoryServices.DirectorySearcher(entry);
   mySearcher.Filter = ("(objectClass=user)");//filte the objectClass type

//    mySearcher.Filter = ("(&(objectCategory=person)(objectClass=user)(sAMAccountName=xxx))");//filte
the objectClass type
   Console.WriteLine("Listing of users in the Active Directory"); 
   Console.WriteLine("========================================");   
 

   foreach(System.DirectoryServices.SearchResult resEnt in mySearcher.FindAll())
   {
    try
    {
     System.DirectoryServices.DirectoryEntry de=resEnt.GetDirectoryEntry();
     Console.WriteLine("Display Name  : " + de.Properties["DisplayName"].Value.ToString());
     Console.WriteLine("Email         : " + de.Properties["Mail"].Value.ToString()); 
     Console.WriteLine("Title         : " + de.Properties["Title"].Value.ToString());   
     Console.WriteLine("User Name     : " + de.Properties["sAMAccountName"].Value.ToString());
     Console.WriteLine("First Name    : " + de.Properties["GivenName"].Value.ToString());     
     Console.WriteLine("Last Name     : " + de.Properties["sn"].Value.ToString()); 
     Console.WriteLine("Initials      : " + de.Properties["Initials"].Value.ToString()); 
     Console.WriteLine("Company       : " + de.Properties["Company"].Value.ToString());
     Console.WriteLine("Department    : " + de.Properties["Department"].Value.ToString());
     Console.WriteLine("Telephone No. : " + de.Properties["TelephoneNumber"].Value.ToString()); 
    }
    catch(Exception e)
    {
    }
    Console.WriteLine("===========    End of user   =============");                                  
    
   }
   Console.WriteLine("===========    End of Listing   =============");

 

 

 

From

Search filterDescription
"(objectClass=*)"All objects.
"(&(objectCategory=person)(objectClass=user)(!cn=andy))"All user objects but "andy".
"(sn=sm*)"All objects with a surname that starts with "sm".
"(&(objectCategory=person)(objectClass=contact)(|(sn=Smith)(sn=Johnson)))"All contacts with a surname equal to "Smith" or "Johnson".

转:https://www.cnblogs.com/stswordman/archive/2006/05/10/396130.html



推荐阅读
author-avatar
杜杜狼2602891895
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有