Hi,
I have a problem with adding user to AD.
Everytime I got "Access denied" :(
Could someone help me ??
Here is my code:
try
{
const string Domain = "name.domain.pl";
const string Container = "OU=Users,OU=IT,DC=name,DC=domain,DC=pl";
const string Username = "xkorytkad";
PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, Domain, Container);
UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(principalContext, Username);
UserPrincipal UserAD = new UserPrincipal(principalContext, "adAdminLogin", "adAdminPassword", true);
UserAD.UserPrincipalName = "testuser";
UserAD.Name = "testuser";
UserAD.GivenName = "testuser";
UserAD.Surname = "testuser";
UserAD.DisplayName = "testuser";
UserAD.Description = "testuser";
UserAD.Enabled = false;
UserAD.Save();
MessageBox.Show("User added successfully :)");
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
Please help :(