title: ADSI Search for DistinguishedName of the primary group based on primarygroupid
body: <p>Because we don't have the active directory module available on all our systems we're using <code>ADSI</code> instead. The following code retrieves a user object from AD by using the <code>AdsiSearcher</code>:</p>
  
  <pre><code>$ADUser = ([AdsiSearcher]"(samaccountname=$SamAccountName)").FindOne()
  </code></pre>
  
  <p>This results in finding the property <code>primarygroupid</code> which represents the domain primary group for user, usually number <code>513</code>. When we have this number we would like to find the <code>distinguishedName</code> of the group. However, the code below does that just fine I was wondering if there is a better <code>filter</code> that can be used instead of filtering after the <code>FindAll()</code> method?</p>
  
  <pre><code>    $searcher = [adsisearcher]'objectclass=group'
      $searcher.PropertiesToLoad.Add('primarygrouptoken')
      $searcher.PropertiesToLoad.Add('distinguishedName')
      $searcher.FindAll() |
      Where-Object { $_.Properties.primarygrouptoken -eq 513}
  </code></pre>
  
  <p>Something like this would be great but it's not possible:</p>
  
  <pre><code>([adsisearcher]”(&amp;(objectCategory=group)(primaryGroupid=513))”).FindOne()
  </code></pre>