Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search active directory for groups like a SQL LIKE statement

Is it possible to search active directory for a group like this: - Give me all groups that contain the name sample?

In SQL I would write

SELECT * FROM GROUP WHERE NAME LIKE %sample%

I found on msdn some hints for expressions =, <= but not for a like. http://msdn.microsoft.com/en-us/library/system.directoryservices.directorysearcher.filter.aspx

Thanks for any hints.

like image 927
yonexbat Avatar asked Jun 17 '26 06:06

yonexbat


2 Answers

Star acts like a wildcard in queries, so that filters like "a*" or "*a" should work.

like image 173
Wiktor Zychla Avatar answered Jun 19 '26 22:06

Wiktor Zychla


If you are just looking to search for the name of the group, the link at the bottom of the page you linked tells you what to do but it does not take you directly to the page

For more information about the LDAP search string format, see "Search Filter Syntax" (I added the correct link)

Use a query like (&(objectclass=group)(cn=*sample*)) will be what you are looking for.

If you are searching if a user is a member of a group, not just a list of all groups that match a pattern, You need to use MemberOf and wildcards do not work on a MemberOf search

like image 34
Scott Chamberlain Avatar answered Jun 20 '26 00:06

Scott Chamberlain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!