LDAP query to get a user memberships in SQL
Today I was struggling to obtain in SQL Server 2005 the list of groups (from Active Directory) to which a user belongs to. Here is the final result. Enjoy it!
EXEC master.dbo.sp_addlinkedserver @server = N'ADSI',
@srvproduct=N'Active Directory Services', @provider=N'ADsDSOObject',
/* get the groups for the user Test1*/
select * from openquery
WHERE objectCategory = ''Group'' AND objectClass = ''group''