简体   繁体   中英

Different result with DirectorySearcher

I wrote a small app to check AD group members. When I execute the following code on my pc, It works well, the SearchResult contains the "member" property, however when I run the same exe on the server or on an another computer the "member" property is missing. The usnchanged and usncreated will be different also. I run the exe with the same user on every pc. What can cause this?

...
using (DirectorySearcher searcher = new DirectorySearcher())
{
    searcher.CacheResults = false;
    searcher.Filter = "(&(objectClass=group)(cn=" + ADName + "))";
    searcher.SizeLimit = int.MaxValue;
    searcher.PageSize = int.MaxValue;
    if (!DirectoryEntry.Exists(ADPath))
    {
        return null;
    }
    searcher.SearchRoot = new DirectoryEntry(ADPath);
    using (SearchResultCollection collection = searcher.FindAll())
    {
        if (collection.Count == 1)
        {
            return collection[0];
        }
    }
}
...

The group membership data is not replicated to the global catalog. The query might work sometimes, if you happen to connect to the domain controller with the actual membership data. On other machines, you probably connect to other domain controllers, of different domains, where the information is not available.

You might want to connect to a domain controller in the actual domain, not to the global catalog.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM