You can add a user as follows:
using (var context = new PrincipalContext(ContextType.Domain))
using (var user = new UserPrincipal(context)
{
UserPrincipalName = "username",
Enabled = true
})
{
user.SetPassword("password");
user.Save();
}
Re: security you can set the application pool identifier to use a privileged service account that has write permissions in Active Directory. Or you can use the constructor overload for PrincipalContext, which takes the username and password for the LDAP connection.
source
share