AD查询的操作:
Code
DirectoryEntry Root = new DirectoryEntry(ADPath, UserName, Password, AuthenticationTypes.Secure);
DirectorySearcher searcher = new DirectorySearcher();
searcher.SearchRoot = Root;
searcher.Filter = "(&(objectclass="+schemaClassNameToSearch+")(samaccountname=" + "" + "*))";
SearchResultCollection results = searcher.FindAll();
参数schemaClassNameToSearch是过滤条件,基本上有以下三个选择,更多选择请参考微软的网站
1. objectClass=organizationalUnit 查询条件是所有的组织单元(OU)
2. objectClass=group 查询条件是所有的组(GROUP)
3. objectClass=user 查询条件是所有的用户(USER)