Reputation: 2793
I'm trying to add users programmatically to AD lDS
instance. Here's how I add a user:
string ldap = "LDAP://xxxx";
var root = new DirectoryEntry(ldap);
var cn = "CN=" + "Joe" + "Blow";
var u = root.Children.Add(cn, "user");
//u.Properties["sAMAccountName"].Value = "jblow";
u.Properties["employeeID"].Value = "654321";
u.Properties["sn"].Value = "Blow";
u.Properties["givenName"].Value = "Joe";
u.Properties["comment"].Value = "a note for you";
u.Properties["homePhone"].Value = "55555555";
u.CommitChanges();
If I execute this code it will successfully add the user Joe Blow
. However, if I try to add username sAMAccountName
I get an error:
The specified directory service attribute or value does not exist.System.Exception {System.DirectoryServices.DirectoryServicesCOMException}
Using ADSI Edit
I looked at the properties of the object and I DO NOT see sAMAccountName
listed there!
How can I add username to AD LDS
instance?
Upvotes: 2
Views: 2934
Reputation: 1157
Look here for an explanation to the problem: http://blog.joeware.net/2011/03/04/2214/
Upvotes: 0
Reputation: 1077
This should provide additional information: INFO
We typically keep the sAMAccountName and userPrincipalName UPN in sync but that can vary depending on your situation/organization.
You can try this:
u.Properties["sAMAccountName"].Add("jblow");
u.Properties["userPrincipalName"].Add("jblow"+ "@" + yourDomain );
Upvotes: 1