title: How to retrieve group by primaryGroupToken from Active Directory using PHP?
body: <p>How can i retrieve a group by it's primaryGroupToken from Active Directory using PHP? Apparently this is a computed attribute so retrieving it is not straight forward, as eluded to in this answer: <a href="https://stackoverflow.com/questions/15827491/ad-group-does-not-have-a-primarygrouptoken-attribute">AD: Group does not have a primaryGroupToken attribute</a></p>
  
  <p>Essentially i'm using the following command:</p>
  
  <pre><code>ldap_search(
      $connection,
      "DC=host,DC=only,DC=network",
      "(&amp;(objectClass=group)(objectCategory=group)(primaryGroupToken=513))",
      array("dn", "primarygrouptoken")
  )
  </code></pre>
  
  <p>Which results in an error:</p>
  
  <pre><code>Warning: ldap_search(): Search: Inappropriate matching
  </code></pre>
  
  <p>Any idea how to retrieve a group using it's primary group token from Active Directory using PHP?</p>