title: How to search for users in Global Catalog within AD forest with multiple trees
body: <p>I have the following AD forest with two trees:</p>
  
  <ol>
  <li>Domain1. Has two child domains Domain2 and Domain3 </li>
  <li>Domain4. Doesn't have child domains.</li>
  </ol>
  
  <p>DNS name of the Domain1 is <em>domain1.local</em>. DNS name of the Domain4 is <em>domain4.local</em>.</p>
  
  <p>In each domain there is a domain controller with Global Catalog enabled.</p>
  
  <p>I'm trying to get UserPrincipal for the user from Domain 4 by its SID. The program runs from a machine in Domain2.</p>
  
  <p>I use the following code:</p>
  
  <pre><code>// Running on some machine from Domain2
  PrincipalContext context = new PrincipalContext(
      ContextType.Domain,
      "dc2.domain2.domain1.local:3268", // Using Global Catalog port and local domain controller
      "DC=domain1, DC=local", // I guess the problem is here
      "domain1\\super-admin", // User has all necessary rights across all domains 
      "password");
  
  UserPrincipal principal = UserPrincipal.FindByIdentity(context, "SID-OF-A-USER-FROM-DOMAIN-4");
  </code></pre>
  
  <p>In my case principal is null (the user was not found).</p>
  
  <p>Searching within one tree (domain1 and its children) works fine with the code snippet above, but I have no idea how to modify the container parameter of the PrincipalContext constructor to really enable forest-wide searches.</p>
  
  <p>Initially I thought that "DC=domain1, DC=local" points to the forest root, but it seems I have  misunderstanding here.</p>
  
  <p>And I know that if I change the container path to "DC=domain4, DC=local" then the search will work, but only for users in domain4. </p>
  
  <p>But I really need such a container path that will point to the entire forest, so I could search for users from any domain within a forest using the same PrincipalContext.</p>
  
  <p>Any help is appreciated, especially if anyone could clarify if my requirements are achievable.</p>