title: LDAP Filter for distinguishedName EndsWith?
body: <p>I'm trying to build an LDAP filter which works like this simple PowerShell command:</p>
  <pre><code>Get-ADUser -Filter * -Properties Department -SearchBase &quot;OU=Company Users,OU=WorkPlace,OU=contoso,DC=fr&quot; | `
      Where{  (($_.SamAccountName -like &quot;user1&quot;) -OR ($_.SamAccountName -like &quot;user2&quot;) -OR ($_.SamAccountName -eq &quot;user3&quot;)) -OR `
              ($_.Department -like &quot;Dpt1/*&quot;) -OR `
              ($_.Department -like &quot;Dpt2/*&quot;) -OR `
              ($_.Department -like &quot;*/Svc3/*&quot;) -OR `
              ($_.SamAccountName -in (Get-ADGroupMember -Identity &quot;Group1&quot; -Recursive).SamAccountName)
           }  
  </code></pre>
  <p>I tried to read some examples <a href="https://social.technet.microsoft.com/wiki/contents/articles/5392.active-directory-ldap-syntax-filters.aspx" rel="nofollow noreferrer">here</a> to make this filter but I'm stuck (error with dn):</p>
  <pre><code>(&amp;(distinguishedName=*OU=Company Users,OU=WorkPlace,OU=contoso,DC=fr)
  (!(employeeNumber=\00))(!(department=\00))
  (|(department=Dpt1/*)(department=Dpt2/*)(department=*/Svc3/*)
  (sAMAccountName=user1)
  (sAMAccountName=user2)
  (sAMAccountName=user3))
  (objectCategory=person)
  (sAMAccountType=805306368))
  </code></pre>
  <p>How can I write this filter to list users with distinguishedName values that end with <code>OU=Company Users,OU=WorkPlace,OU=contoso,DC=fr</code> or which are in this OU and subOUs?</p>
  <p>If it helps users that I need to filter:</p>
  <ul>
  <li>need to be in the specified OU or subOUs</li>
  <li>need to match some samAccountNames OR Department OR Nested memberShip of a group</li>
  <li>need to have some attributes filled (department, employeenumber, ...)</li>
  </ul>