我有在C#创建通过LDAP电脑问题:C#创建在Active Directory中的计算机 - 小学组问题
以下是我的代码:
C#
string connectionPrefix = "LDAP://" + ldapPath;
DirectoryEntry dirEntry = new DirectoryEntry(connectionPrefix, GlobalVar.adUser, GlobalVar.adUserPassword);
DirectoryEntry newComputer = dirEntry.Children.Add("CN=" + computerName, "computer");
newComputer.Properties["samaccountname"].Value = computerName;
newComputer.Properties["dnshostname"].Value = computerName + ".[privacy].[domain].[here]";
newComputer.Properties["description"].Value = GlobalVar.adUser;
newComputer.Properties["location"].Value = "IT";
这完美的作品但有一个例外:计算机是在正确的文件夹中创建的。但是,当我直接在AD中创建计算机时,主要组是“域用户”而不是“域计算机”,则计算机会自动分配主组“域计算机”
结果是我无法将计算机添加到该域名无需在广告中手动修改。
任何解决方案?
最好的问候,
朱利安
您使用的是.net 3.5或以上版本? – TonyW
我确实使用.Net 4.5 –