我正在嘗試做一個非常簡單的AD查詢,以查看計算機是否在組中。下面的代碼看起來很直觀,但不起作用。對於NetBIOSName引用的計算機是memberOf的組,該LDAPString是完全可識別的名稱。Active Directory - 在組中查找計算機
public bool IsComputerInADGroup(String LDAPString, String NetBIOSName)
{
using (DirectoryEntry entry = new DirectoryEntry(String.Format(@"LDAP://{0}", LDAPString)))
using (DirectorySearcher computerSearch = new DirectorySearcher(entry))
{
ComputerSearch.Filter = String.Format("(&(objectCategory=computer)(CN={0}))", NetBIOSName);
SearchResult match = ComputerSearch.FindOne();
if (match != null)
{
return true;
}
}
return false;
}
有人能解釋爲什麼這是不正確的,什麼是正確/最快的方式來執行此搜索。
感謝 P
感謝您抽出時間來解釋。這是有道理的,是一種享受。 – user474541 2010-11-15 11:23:12