轻型目录服务实例中缺少 sAMAccountName

sAMAccountName is missing from Lightweight Directory Services instance

我正在尝试以编程方式将用户添加到 AD lDS 实例。这是我添加用户的方法:

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();

如果我执行此代码,它将成功添加用户 Joe Blow。但是,如果我尝试添加用户名 sAMAccountName,则会出现错误:

The specified directory service attribute or value does not exist.System.Exception {System.DirectoryServices.DirectoryServicesCOMException}

使用 ADSI Edit 我查看了对象的属性,但没有看到 sAMAccountName 列在那里!

如何将用户名添加到 AD LDS 实例?

这应该提供额外的信息:INFO

我们通常会保持 sAMAccountName 和 userPrincipalName UPN 同步,但这可能会因您的 situation/organization 而异。

你可以试试这个:

u.Properties["sAMAccountName"].Add("jblow"); u.Properties["userPrincipalName"].Add("jblow"+ "@" + yourDomain );

在此处查找问题的解释: http://blog.joeware.net/2011/03/04/2214/