【发布时间】:2015-02-05 16:41:27
【问题描述】:
我正在尝试以编程方式将用户添加到 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,则会收到错误消息:
指定的目录服务属性或值不存在。System.Exception {System.DirectoryServices.DirectoryServicesCOMException}
使用ADSI Edit 我查看了对象的属性,但我没有看到sAMAccountName 在那里列出!
如何将用户名添加到AD LDS 实例?
【问题讨论】:
-
Readers:此脚本快速将 sAMAccountName 属性添加到架构中。我已经使用它并且它可以工作,但是将脚本保存为 unicode(请参阅 cmets),并且您可能还需要在运行时在“#configurationNamingContext”参数周围添加引号(请参阅文件中的说明)。脚本链接:gist.github.com/Nora-Ballard/9124822
标签: c# console-application adlds