使用 DirectoryServices 创建用户帐户时出现奇怪的 sAMAccountName
我的 C# 代码使用 DirectoryServices 命名空间来创建域用户帐户。
DirectoryEntry deRoot = new DirectoryEntry("LDAP://OU=MYOU,DC=DOMAIN,DC=LOCAL");
directoryEntry = deRoot.Children.Add("CN=Tony", "user");
directoryEntry.CommitChanges();
directoryEntry.Properties["sAMAccountName"].Value = "Tony1";
directoryEntry.Properties["displayName"].Value = "Tony Danza";
directoryEntry.Invoke("SetPassword", "mypass123");
directoryEntry.CommitChanges();
这成功创建了帐户,但 sAMAccountName 属性包含一个相当奇怪的值,例如 $HGA000-8FP94NQK9R9I 或 $NGA000-B3BJ2ELT5OOD。 当在我的开发域内执行时,一切都很好。
my C# code uses the DirectoryServices namespace to create domain user accounts.
DirectoryEntry deRoot = new DirectoryEntry("LDAP://OU=MYOU,DC=DOMAIN,DC=LOCAL");
directoryEntry = deRoot.Children.Add("CN=Tony", "user");
directoryEntry.CommitChanges();
directoryEntry.Properties["sAMAccountName"].Value = "Tony1";
directoryEntry.Properties["displayName"].Value = "Tony Danza";
directoryEntry.Invoke("SetPassword", "mypass123");
directoryEntry.CommitChanges();
This successfully creates the account but the sAMAccountName property contains a rather weird value like $HGA000-8FP94NQK9R9I or $NGA000-B3BJ2ELT5OOD.
When executed inside my dev-domain, everything's fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在第一个
CommitChanges
之前设置 sAMAccountName。也许,由于 sAMAccountName 是必需属性,如果您在创建对象时未提供它,系统会为其提供默认值。
Try setting the sAMAccountName before the first
CommitChanges
.Maybe, since sAMAccountName is a required attribute, the system gives it a default value if you don't provide it when you create the object.