Sunday, January 18, 2009

C#: Add New User in LDAP

This code shows how to create a new user in AD

public static DirectoryEntry CreateNewUser(string cn)
{
//set the LDAP qualification so that the user will be created under the Users
//container
string LDAPDomain ="/CN=Users," + GetLDAPDomain();
DirectoryEntry oDE= GetDirectoryObject(LDAPDomain);
DirectoryEntry user = oDE.Children.Add("CN=" + cn, "user");
//Must commit changes to initially create user

user.CommitChanges();
oDE.Close();
oDE.Dispose();
return user;
}

No comments:

Post a Comment