title: How to search in multiple domains using System.DirectoryServices.AccountManagement?
body: <p>I have three or more domains like <code>main.com</code>, <code>sub.main.com</code>, <code>sub2.main.com</code> and etc</p>
  
  <p>I have a code:</p>
  
  <pre><code>using (PrincipalContext ctx = 
      new PrincipalContext(ContextType.Domain, "ADServer", 
      "dc=main,dc=com", ContextOptions.Negotiate))
  {
      UserPrincipal u = new UserPrincipal(ctx);
      u.UserPrincipalName = "*" + mask + "*";
  
      using (PrincipalSearcher ps = new PrincipalSearcher(u))
      {
         PrincipalSearchResult&lt;Principal&gt; results = ps.FindAll();
         List&lt;ADUser&gt; lst = new List&lt;ADUser&gt;();
  
         foreach (var item in results.Cast&lt;UserPrincipal&gt;().Take(15))
         {
             byte[] sid = new byte[item.Sid.BinaryLength];
             item.Sid.GetBinaryForm(sid, 0);
  
             ADUser us = new ADUser()
             {
                 Sid = sid,
                 Account = item.SamAccountName,
                 FullName = item.DisplayName
             };
  
             lst.Add(us);
         }
  
      }
  
      return lst;
  }
  </code></pre>
  
  <p>But it searches within only one domain: <code>main.com</code>.</p>
  
  <p>How can I search records in all domains at one time?</p>