# Return List of Users with LDAP Query

**URL:** <https://forum.ansible.com/t/return-list-of-users-with-ldap-query/35684>\
**Category:** Ansible Project\
**Created:** [August 27, 2021, 4:06pm UTC](https://forum.ansible.com/t/return-list-of-users-with-ldap-query/35684 "2021-08-27T16:06:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![david.burtton](https://avatars.discourse-cdn.com/v4/letter/d/f08c70/32.png) [@david.burtton](https://forum.ansible.com/u/david.burtton)\
**Post date:** [August 27, 2021, 4:06pm UTC](https://forum.ansible.com/t/return-list-of-users-with-ldap-query/35684/1 "2021-08-27T16:06:07Z")

</div>

Hi All,

I’m trying to use Ansible to query my Domain Controller to return a list of users with a specific set of criteria and then modify those returned users to add them to a group.

How this looks in practice is that I want Ansible to return a list of users based on this query:

(&(objectClass=User)(extensionAttribute10=AttribPresent)(!(memberOf=CN=MyGroup,OU=MyOU2,OU=MyOU,DC=Domain)))

This returns a list of users that I want to loop over and add to a group in AD: DaveGroup.

So far I can’t seem to find a way to do this, other than with PowerShell maybe?

Any help would be amazing!

Thanks

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [August 27, 2021, 7:23pm UTC](https://forum.ansible.com/t/return-list-of-users-with-ldap-query/35684/2 "2021-08-27T19:23:17Z")

</div>

Take a look at the ldapsearch lookup plugin:

[https://docs.ansible.com/ansible/latest/collections/community/general/ldap\_search\_module.html](https://docs.ansible.com/ansible/latest/collections/community/general/ldap_search_module.html)
