1. Execute line below on your SQL Server to link server and AD:
[PHP]EXEC sp_addlinkedserver 'ADSI', 'Active Directory Service Interfaces', 'ADSDSOObject', 'adsdatasource'[/PHP]
2. Change From in query below. It is just an example you have to write your own query.
[PHP] SELECT * FROM OPENQUERY( ADSI,
'SELECT name, adsPath
FROM ''LDAP://DC=....,DC=....,DC=...,DC=com''
WHERE objectCategory = ''Person'' AND objectClass= ''user''')[/PHP]
Also you have to be aware that SQL query has limitation with AD.
1. It has a limit of 1000 records returned at a time. I have a work around if you'll really need it.
2. There is no way to return multiple results like group memberships (if you know what it is). Whenever AD tries to return an object it can not be done through SQL.
Thank you.