get LDAP user using sql server query?

Sagarp
Posted by Sagarp under ASP.NET category on | Views : 5424
sp_addlinkedserver 'ADSI', 'Active Directory Service Interfaces', 'ADSDSOObject', 'adsdatasource'



--only get all users

SELECT * FROM OpenQuery(ADSI, 'SELECT GivenName, sn,sAMAccountName, cn, mail, displayName, department, telephoneNumber,mobile,streetAddress, st, distinguishedName, physicalDeliveryOfficeName FROM ''LDAP://DC=emanon,DC=com'' WHERE objectClass=''User''')

--only get all grops


SELECT * FROM OpenQuery(ADSI, 'SELECT groupMembershipSAM,title,PwdLastSet, GivenName, sn,sAMAccountName, cn, mail, displayName, department, telephoneNumber,streetAddress, st, distinguishedName, physicalDeliveryOfficeName FROM ''LDAP://DC=domain,DC=com'' WHERE objectClass=''group''')

--get all users ans grups
SELECT * FROM OpenQuery(ADSI, 'SELECT title,PwdLastSet, GivenName, sn,sAMAccountName, cn, mail, displayName, department, telephoneNumber,streetAddress, st, distinguishedName, physicalDeliveryOfficeName FROM ''LDAP://DC=domain,DC=com'' WHERE objectClass=''User'' AND objectClass=''group''')

Comments or Responses

Login to post response