title: Get all users from active directory to sharepoint
body: <p>I have to populate my autocomplete PeopleEditor-like control based on brililant <a href="https://github.com/harindaka/ASPTokenInput" rel="noreferrer">ASPTokenInput</a> with all people from my AD domain. Reflecting PeopleEditor shows a real mess in their Active Directory search engine and all potentially helpful classes are internal. </p>
  
  <p>My test method works fine, but I need to get ALL users from AD(not sharepoint site ones) to populate my list:
  <img src="https://i.stack.imgur.com/Tcz8m.png" alt="How it looks"></p>
  
  <pre><code>public string GetUsers(string filter)
      {
          var spWeb = SPContext.Current.Web;
          SPUserCollection allusers = spWeb.AllUsers;
          List&lt;SPUser&gt; users = allusers.Cast&lt;SPUser&gt;().ToList();
          var query = from spUser in users.Select(usr =&gt; new {id = usr.ID, name = usr.Name})
                          .Where(p =&gt; p.name.IndexOf(filter, StringComparison.InvariantCultureIgnoreCase) &gt;= 0)
                      select new {id = spUser.id.ToString(), spUser.name};
  
          return new JavaScriptSerializer().Serialize(query);
      }
  </code></pre>
  
  <p>How can I query active directory like this? Is it possible to retrieve all AD connection settings from sharepoint itself? I need just id and user name to fill my dropdownlist Converting this to SPUserCollection is another big deal.</p>
  
  <p>It would be great to use some built-in SP methods like this:</p>
  
  <pre><code> [SubsetCallableExcludeMember(SubsetCallableExcludeMemberType.UnsupportedSPType)]
  public static IList&lt;SPPrincipalInfo&gt; SearchWindowsPrincipals(SPWebApplication webApp, string input, SPPrincipalType scopes, int maxCount, out bool reachMaxCount)
  </code></pre>