SQL Server Performance

Getting MemberOf field from LDAP Query

Discussion in 'SQL Server 2005 General Developer Questions' started by danny123, Nov 13, 2008.

  1. danny123 New Member

    Hi there,
    I want to find whether specific user is member of the particular distribution group in AD or not. But when i am trying to get memberof field from AD using LDAP i am not getting any values. here is what i am using.
    So i know the input parameter of User Name and Group i want to look into.
    SELECT [Name], userPrincipalName, samAccountName,department,memberof
    FROM OPENQUERY( ADSI,
    'SELECT Name, userPrincipalName, samAccountName,department,memberof
    FROM ''LDAP://Test/ DC=Test1,dC=Test2''
    WHERE objectCategory=''person''
    AND objectClass=''user'' AND samAccountName=''User-N'' and memberOf=''cn=TestGroup,dc=Test1,dc=Test2''')
    Is there something i am missing?
    Thanks!
  2. danny123 New Member

    I got it done. I was missing the Gruop type information for the MemberOf field.
    So this is the query :
    SELECT [Name], userPrincipalName, samAccountName,department,memberof
    FROM OPENQUERY( ADSI,
    'SELECT Name, userPrincipalName, samAccountName,department,memberof
    FROM ''LDAP://Test/ DC=Test1,dC=Test2''
    WHERE objectCategory=''person''
    AND objectClass=''user'' AND samAccountName=''User-N'' and memberOf=''cn=TestGroup,OU=Custom Group,dc=Test1,dc=Test2''')
    Thanks!

Share This Page