Using DirectorySearcher to query multiple OUs

有些话、适合烂在心里 提交于 2019-12-08 08:09:47

问题


I have the following code:

var directoryEntry = new DirectoryEntry(distributionListsListADSPath);
var directorySearcher = new DirectorySearcher(directoryEntry) 
          { SizeLimit = int.MaxValue, PageSize = int.MaxValue };
var result = directorySearcher.FindAll();

The problem is I want to search two seperate OUs.

So what I do is run through this twice, once where

private const string distributionListsListADSPath = 
"LDAP://OU=Distribution Lists,OU=Groups,DC=enron,DC=com";

and a second where it is

private const string distributionListsListADSPath = 
"LDAP://OU=Security Groups,OU=Groups,DC=enron,DC=com";

Ideally, I could do something like

private const string distributionListsListADSPath = 
"LDAP://OU=Distribution Lists | OU = Security Groups ,OU=Groups,DC=enron,DC=com";

回答1:


Without knowing the hierarchy of your container, it is hard to form a proper answer.

You may need to use Extensible Match which is described here: http://ldapwiki.willeke.com/wiki/ExtensibleMatch

Good Luck -jim




回答2:


try this:

"(|(OU=Distribution Lists)(OU=Security Groups,OU=Groups,DC=enron,DC=com))"


来源:https://stackoverflow.com/questions/1540595/using-directorysearcher-to-query-multiple-ous

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!