首页 > 其他 > 详细

HOW DO YOU DO: CREATE AD USER AND ADD THIS INTO GROUP

时间:2014-10-09 22:26:52      阅读:418      评论:0      收藏:0      [点我收藏+]

Liunx:
static void Main(string[] args)
       {
           try
           {
               string[] groups = new string[] { "Admin", "Back_End", "CSharp", "Developer", "Faserati", "Flex", "Front-End", "HTML", "JS", "SQL", "Teacher", "Tester" };

               DirectoryEntry root = new DirectoryEntry();
               root.Path = "LDAP://FAST.Faserati/CN=Users,DC=FAST,DC=Faserati";
               root.Username = "Administrator";
               root.Password = "P@$$w0rd";

               DirectoryEntry group = new DirectoryEntry();
               group.Path = "LDAP://FAST.Faserati";
               group.Username = "Administrator";
               group.Password = "P@$$w0rd";
               group.Children.SchemaFilter.Add("group");
               for (int i = 0; i < 10000; i++)
               {
                   Random r = new Random();
                   string g = groups[r.Next(0, 11)];

                   DirectoryEntry parent = group.Children.Find("CN=" + g);
                   parent.Invoke("Add", CreateUser(root, g + i.ToString()).Path.ToString());

               }
           }
           catch (COMException ex)
           {
               Console.WriteLine(ex.Message);
           }
       }

       static DirectoryEntry CreateUser(DirectoryEntry root, string userName)
       {
           using (var de = new DirectoryEntry())
           {
               de.Path = "LDAP://FAST.Faserati/CN=Users,DC=FAST,DC=Faserati";
               de.Username = "Administrator";
               de.Password = "P@$$w0rd";
               DirectoryEntry user = root.Children.Add("CN=" + userName, "user");
               user.Properties["company"].Add("Faserati");
               user.Properties["employeeID"].Add("4711");
               user.Properties["samAccountName"].Add(userName);
               user.Properties["userPrincipalName"].Add(userName + "@explorer.local");
               user.Properties["sn"].Add("Doe");
               user.Properties["mail"].Add(userName + "@Faserati.com");
               user.Properties["userPassword"].Add("someSecret");
               user.Properties["userAccountControl"].Add(544);
               user.CommitChanges();

               return user;
           }
          
Windows:
http://technet.microsoft.com/en-us/library/cc783256(v=ws.10).aspx

http://wenku.baidu.com/link?url=LewnAPwN0b7KLzTqm6L6yUWIL4s8ulFAZS4beoBoAAEtQ0AkFNZJC0p27n9ynArElwXlDOqq86VvkPyJMapTiAk8yjg8_BvcXWIkcL9apkm

HOW DO YOU DO: CREATE AD USER AND ADD THIS INTO GROUP

原文:http://www.cnblogs.com/lzhairs/p/4014531.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!