启用 AD 帐户时出现重复条目错误
我试图以编程方式将用户添加到 Active Directory,但总是遇到错误 - 无论我在启用帐户后创建什么用户,都会引发“重复条目”错误。这是我正在使用的代码:
DirectoryEntry NewUser = AD.Children.Add("CN=" + username, "User");
NewUser.CommitChanges();
//Add user information
NewUser.Invoke("SetPassword", password);
NewUser.Properties["givenName"].Value = FirstName;
NewUser.Properties["sn"].Value = LastName;
NewUser.Properties["mail"].Value = email;
NewUser.Properties["userPrincipalName"].Value = username + @"domainname";
NewUser.Properties["userAccountControl"].Add(0x200);//enable account
NewUser.CommitChanges();
当我注释掉更改 userAccountControl 的行时,一切正常。我什至尝试创建一个新条目并使用以下代码以这种方式修改它:
DirectoryEntry editUser = getUserEntry(username);
editUser.Properties["userAccountControl"].Add(0x200);//enable account
editUser.CommitChanges();
但这仍然会引发相同的错误。 getUserEntry 只是从 AD 中获取给定用户名的目录条目。谁能看出在这种情况下会发生重复输入错误的原因吗?
I am trying to add users to Active Directory programmatically and I keep running into an error - no matter what user I create as soon as I enable the account a "Duplicate Entry " error is thrown. This is the code that I am using:
DirectoryEntry NewUser = AD.Children.Add("CN=" + username, "User");
NewUser.CommitChanges();
//Add user information
NewUser.Invoke("SetPassword", password);
NewUser.Properties["givenName"].Value = FirstName;
NewUser.Properties["sn"].Value = LastName;
NewUser.Properties["mail"].Value = email;
NewUser.Properties["userPrincipalName"].Value = username + @"domainname";
NewUser.Properties["userAccountControl"].Add(0x200);//enable account
NewUser.CommitChanges();
When I comment out the line that changes the userAccountControl, everything works fine. I even tried to create a new entry and modify it that way using this code:
DirectoryEntry editUser = getUserEntry(username);
editUser.Properties["userAccountControl"].Add(0x200);//enable account
editUser.CommitChanges();
but that still throws the same error. getUserEntry just grabs the directory entry from AD given the username. Can anyone see a reason why a duplicate entry error would occur in this case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试替换为:
您可能知道某些属性可以是多值的,
userAccountControl
不能,但是在您的代码中这就是您尝试做的,我意味着对其进行多值化。在我的代码中,我只是分配一个新值(它将在 vue 的纯 LDAP 点上进行替换)。Can you try to replace by :
You probably know that some attributes can be multi-valued,
userAccountControl
can't, but in your code that's what you try to do, I mean to multi-value it. In my code I just assign a new value (it's going to play a replace on the pure LDAP point of vue).