I have two queries that retrieve all groups and all users in a domain, Mydomain
--; Get all groups in domain MyDomain
select *
from OpenQuery(ADSI,
SELECT samaccountname,mail,sn,name, cn, objectCategory
FROM LDAP://Mydomain/CN=users,DC=Mydomain,DC=com
WHERE objectCategory= group
ORDER BY cn
)
--; Get all users in domain MyDomain
select *
from OpenQuery(ADSI,
SELECT objectCategory, cn, sn, mail, name, department,samaccountname
FROM LDAP://Mydomaindomain/CN=users,DC=Mydomain,DC=com
WHERE objectCategory= user
ORDER BY cn
)
-- where samaccountname= mylogin
What I would like to find out is,
How do you retrieve a list of all groups in MyDomain
that a particular user belongs to?
[UPDATE] I was able to get the opposite result
Given the group name, retrieve all users
select *
from OpenQuery(ADSI,
SELECT objectCategory, cn, sn, mail, name, department
FROM LDAP://Mydomain/CN=users,DC=wl-domain,DC=com
WHERE MemberOf= cn=_____GROUPNAME_____,CN=users,DC=Mydomain,DC=com
ORDER BY cn
)