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;
            }
        }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-30
  • 2022-12-23
  • 2021-05-21
  • 2022-12-23
  • 2022-12-23
  • 2021-09-17
猜你喜欢
  • 2022-01-08
  • 2021-09-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-06
相关资源
相似解决方案