Search code examples
sql-server-2008t-sqlldapssmsldap-query

get username and mobile from LDAP from a certain group


I need a list of phonenumbers from our AD/LDAP from a certain group for our SMS service.

The problem is that I need to filter on this group to get the phone numbers if this certain users.

The users are in a group/cn with a certain ou. If I search for the group I get this information:

''LDAP://CN=<< Groupname of the users need to be selected >>,OU=Programs,OU=Resources,DC=< domainname >,DC=com''

Is it possible to get the mobile field of the users of this cn or is there another way to do this?


Solution

  • Thank you Jim,

    It helped me in the right direction.

    The final solution:

    SELECT  *  
    FROM    OPENQUERY(ADSI,'
                            SELECT telephoneNumber, name
                            FROM ''LDAP://<domainname>.com/ou=accounts,DC=<domainname>,DC=com''
                            WHERE objectCategory = ''Person'' AND objectClass = ''user''
                                AND memberOf=''CN=<groupname>,OU=Programs,OU=Resources,DC=<domainname>,DC=com''
                            ')