I can query for users with the following, but I would like to add an additional OU=Good to the search DN. Is this possible without hard coding the full path to the GC?
Forest myForest = Forest.GetCurrentForest();
GlobalCatalog cat = myForest.FindGlobalCatalog();
DirectorySearcher srch = cat.GetDirectorySearcher();
srch.Filter = "(&(objectClass=user)(samaccountname=myuser))";
SearchResult result = srch.FindOne();
You might try to get the
DirectoryEntryfor your global catalog, and then search its.Childrenproperty for the OU you’re looking for, and then use thatDirectoryEntryas your search root – something like (untested, don’t have AD at hand to test):Of course, in reality, you’d want to add some error checking (
!= nulland so on) to your code – but that would be the basic way of getting at your OU (I hope!)