LDAP Filter Syntax Query

116 views Asked by At

What would be the syntax for LDAP for the below scenario:

Where sAMAccountName = GRA-* without $. I want the records which are highlighted in green.

This is my current LADP Filter for your reference:

(&(objectClass=user)sAMAccountName=GRA-*))

Anyone, Please help with the correct syntax.

1

There are 1 answers

0
Gabriel Luci On

Your filter can work, but you're missing a ( in front of sAMAccountName:

(&(objectClass=user)(sAMAccountName=GRA-*))

But you may be able to do better. If those ones that end in $ are computer objects (which always have sAMAccountNames that end in $, but also have an objectClass of user), then you can make sure you only get user objects by including (objectCategory=person):

(&(objectClass=user)(objectCategory=person)(sAMAccountName=GRA-*))

If, for whatever reason, those $ objects are actually user accounts, then you can exclude them with (!sAMAccountName=*$):

(&(objectClass=user)(objectCategory=person)(sAMAccountName=GRA-*)(!sAMAccountName=*$))