0

I have a somewhat particular situation I couldn't find answers to through google.

I need to query my active directory for users whose SAMAccountName fits a particular pattern (3 letters followed by 4 digits).

Currently I pull the entire list of users and filter it with regex client-side.

Can this somehow be done directly in the query so that only users with that matching field are returned from the server in the first place?

mvi2110
  • 31
  • 5
  • Any three letters followed by any four digits? Or are the letters always the same? Maybe can you give us the regex you use? – Gabriel Luci Sep 28 '22 at 14:43
  • @GabrielLuci Any three letters followed by any four digits, yes. Both the letters and digits are randomly generated for each user. – mvi2110 Sep 28 '22 at 17:24

1 Answers1

0

Unfortunately, the best you can do is limit it to accounts where the first character is a letter.

The only operators that could help are >= and <=. For example, you can have a filter like this:

(&(sAMAccountName>=A*)(sAMAccountName<=Z*))

That will exclude accounts that start with anything other than a letter. But there is no way to extend that to any more than just the first character.

I'm guessing that probably isn't going to help.

More reading: Active Directory: LDAP Syntax Filters

Gabriel Luci
  • 38,328
  • 4
  • 55
  • 84