title: How to find global catalog of Active Directory?
body: <p>I want to search for users in an Active Directory environment with <code>GC://DC=xxx,DC=yyy,DC=zzz</code> format. But how can I programmatically find the global catalogs in an arbitary Active Directory environment? Does each domain name correspond to a global catalog always? Any alternative means I can try?</p>
  
  <p>Note: The <code>Forest.FindAllGlobalCatalogs()</code> returns a list of server names but I'm actually not able to search using them.</p>
  
  <p>Edit1: Here's what I want to do : Suppose my activedirectory has a domain called domain1.root.com, then I will use GC://DC=domain1,DC=root,DC=com to search for a user. But is this always a Global catalog? Must every domain have a global catalog?</p>
  
  <p>Edit2: I am now able to search for users using the following code:</p>
  
  <pre><code>            var currentForest = Forest.GetCurrentForest();
              var globalCatalog = currentForest.FindGlobalCatalog();
              Console.WriteLine(globalCatalog.Name);
              //DirectorySearcher searcher = new DirectorySearcher("GC://"+y.Name);
              DirectorySearcher searcher = globalCatalog.GetDirectorySearcher();
              searcher.Filter = @"samaccountname=skaranth";
              Console.WriteLine(searcher.SearchRoot.Path);
              var result = searcher.FindOne();
              if(result!=null)
                  Console.WriteLine(result.Properties["distinguishedname"][0]);
              searcher.Dispose();
              globalCatalog.Dispose();
              currentForest.Dispose();
  </code></pre>