2011-03-09 57 views

回答

1

可以使用的System.DirectoryServices

// 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(); 

通過C#代碼做到這一點見http://msdn.microsoft.com/en-us/library/ms180832(v=VS.90).aspx的例子。

+0

或他所說的。 :-) – Ben 2011-03-09 10:16:27

+0

這不適用於我不知道爲什麼。它返回成功,但電腦不會被添加。 – Rama 2013-01-09 09:06:18

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; 
} 

//第3步:添加PC到廣告組
groupEntry.Invoke( 「添加」,computerdn);

相關問題