我正在尝试以编程方式将计算机添加到我公司的 Active Directory。
我在互联网上搜索了很长时间,但找不到解决方案。
My code:
DirectoryEntry dirEntry = new DirectoryEntry("LDAP://OU=ou2example,OU=ou1example,DC=site,DC=company,DC=com");
dirEntry.Username = "username";
dirEntry.Password = "password";
DirectoryEntry newComputer = dirEntry.Children.Add("CN=" + ComputerName, "computer");
newComputer.CommitChanges();
我的问题:
计算机已添加到 Active Directory。但它被标记为禁用。
我尝试按照以下方式启用计算机:
newComputer.Properties["userAccountControl"].Value = 0x200;
但我得到一个 DirectoryServicesCOMException --> 服务器无法完成请求。
or
newComputer.Properties["Enabled"].Value = true;
但我得到一个 DirectoryServicesCOMException --> 请求的操作不满足至少一个针对该对象类条件的约束。
请注意,例外情况已从德语翻译成英语!
感谢您的帮助!
我认为有两件事可能是错误的,但我已经很长时间没有做过这样的事情了,所以我可能错了......
首先,什么时候设置userAccountControl
旗帜?我似乎记得你应该在CommitChanges
对于新条目。像这样:
DirectoryEntry newComputer =
dirEntry.Children.Add("CN=" + ComputerName, "computer");
newComputer.CommitChanges();
newComputer.Properties["userAccountControl"].Value = 0x200;
newComputer.CommitChanges();
其次,您可以尝试设置UF_WORKSTATION_TRUST_ACCOUNT http://www.selfadsi.org/ads-attributes/user-userAccountControl.htm#UF_WORKSTATION_TRUST_ACCOUNT flag (0x1000
) 代替UF_NORMAL_ACCOUNT http://www.selfadsi.org/ads-attributes/user-userAccountControl.htm#UF_NORMAL_ACCOUNT (0x200
).
您还可以检查一下是否sAMAccountType
该条目的SAM_MACHINE_ACCOUNT
(0x30000001
)。我认为这应该是自动的,但检查一下也没什么坏处。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)