Found this old thread in the "Related" section.
There are two more suggestions on this.
Each of them can receive objects in the memberOf attribute directly as SearchResult in one search.
All code is in C #.
Attribute Scope Request (ASQ):
DirectoryEntry userEntry = new DirectoryEntry("LDAP://<server>/<user DN>", "user", "pwd"); DirectorySearcher searcher = new DirectorySearcher(userEntry); searcher.SearchScope = SearchScope.Base; searcher.AttributeScopeQuery = "memberOf"; searcher.PropertiesToLoad.Clear(); // just load any attributes you want, not limited to cn searcher.PropertiesToLoad.Add("cn"); foreach (SearchResult result in searcher.FindAll()) { Console.WriteLine(result.Path); }
Limitations:
- Do not process primary group membership
- Functional level of 2003 is required (forgot domain / forest)
- ASQ does not work across the domain (at least System.DirectoryServices cannot, it will throw an exception for any object in another domain)
LDAP_MATCHING_RULE_IN_CHAIN matching rule:
DirectoryEntry rootEntry = new DirectoryEntry("GC://<GC server>", "user", "pwd"); DirectorySearcher searcher = new DirectorySearcher(rootEntry); searcher.SearchScope = SearchScope.Subtree; searcher.Filter = "(member:1.2.840.113556.1.4.1941:=<user DN>)"; searcher.PropertiesToLoad.Clear(); // just load any attributes you want, not limited to cn searcher.PropertiesToLoad.Add("cn"); foreach (SearchResult result in searcher.FindAll()) { Console.WriteLine(result.Path); }
Limitations:
- Do not process primary group membership
- Functional level 2008 R2 is required (forgot domain / forest)
- it gets nested group membership, not just one memberOf level
source share