Create Active Directory user in .NET (C#)

前端 未结 3 1996
情深已故
情深已故 2021-02-01 06:08

I need to create a new user in Active Directory. I have found several examples like the following:

using System;
using System.DirectoryServices;

namespace test          


        
3条回答
  •  暖寄归人
    2021-02-01 06:29

    Check the below code

     DirectoryEntry ouEntry = new DirectoryEntry("LDAP://OU=TestOU,DC=TestDomain,DC=local");
    
            for (int i = 3; i < 6; i++)
            {
                try
                {
                    DirectoryEntry childEntry = ouEntry.Children.Add("CN=TestUser" + i, "user");
                    childEntry.CommitChanges();
                    ouEntry.CommitChanges();
                    childEntry.Invoke("SetPassword", new object[] { "password" });
                    childEntry.CommitChanges();
                }
                catch (Exception ex)
                {
    
                }
            }
    

提交回复
热议问题