我有一个要求,我必须将计算机名称添加到预定义的活动目录组。有没有人有这方面的经验?
问问题
3538 次
3 回答
1
您可以使用 System.DirectoryServices 通过 C# 代码执行此操作
// Bind to the Computers container and add a new computer.
DirectoryEntry de01 = new DirectoryEntry("LDAP://CN=Computers,DC=fabrikam,DC=com");
DirectoryEntry newComputer = de01.Children.Add("CN=New Computer", "computer");
newGroup.CommitChanges();
有关示例,请参见http://msdn.microsoft.com/en-us/library/ms180832(v=VS.90).aspx。
于 2011-03-09T10:15:15.883 回答
0
使用 ADSI。基本上,您绑定到 Active Directory,找到您需要的计算机对象和组对象,然后调用方法将计算机添加到组中。
如果需要使用命令行,您可以使用 WSH 或 .Net 轻松完成此操作。
ADSI 参考: http: //msdn.microsoft.com/en-us/library/aa772218 (v=VS.85).aspx
ADSI LDAP: http: //msdn.microsoft.com/en-us/library/aa746384 (v=VS.85).aspx
直到计算机重新启动后才会生效。
于 2011-03-09T10:15:50.567 回答
0
下面的代码对我有用
//Step 1: get the DN of the adgroup you want to use
DirectoryEntry groupEntry = new DirectoryEntry ("LDAP://CN=AdgroupNameWewantToAddTo,DC=na,DC=ABCint,DC=com");//adgroupDSN
//step 2: get the Dn of the pc you want to add to the group string memberDN; DirectorySearcher dom = new DirectorySearcher(baseDN); dom.Filter = "(&(ObjectCategory=computer) (cn=" + PCNAME+ "))"; SearchResult searchResult = dom.FindOne(); if (searchResult != null) { memberDN=searchResult.GetDirectoryEntry().Path; }
//第三步:添加PC到广告组
groupEntry.Invoke("Add", computerdn);
于 2013-01-09T09:23:59.573 回答