Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Convert LDAP query to SQL ADSI

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-08-16 : 09:29:11
Bill writes "I would like to start off by saying I am no "SQL guru". I am the Systems Admin for a small company whose role is to assist our contract SQL guy with getting something working. Point being, please excuse me if some of my terms are not that of a "SQL guy" - my area of expertise is working with Active Directory.

The hope.

From a SQL 2005 query window, we would like to use an ADSI query of an Active Directory group. This query should produce a list of users that will in turn be used to populate certain fields in a database. Depending on which fields in the database are populated determines a given users access to the application. Make sense?

The problem.

Using Active Directory Users and Computers (ADUC) advanced search window (Exp A below), I can produce a list of users that belong to group A, but using the ADSI search from "Exp B" returns nothing? We have tried changing the parameters of the WHERE clause from objectClass = ''User'' to ObjectCategory=''user'' - trying to match the LDAP query but this did not help.

Is there a way to convert my (Exp A) ADUC search to an ADSI query?

Thank You

Bill



* Exp A:

(&(objectCategory=user)(memberOf=CN=groupname,OU=ouname,DC=domainname,DC=com))

* Exp B:

SELECT *

FROM OPENROWSET(

'AdsDsoObject'

,'User ID=;Password=;ADSI Flag=0x11;Page Size=10000'

,'SELECT mail

,SamAccountName

,givenName

,Name

,SN

,distinguishedName

FROM ''LDAP://DC=domainname,DC=com''

WHERE objectClass = ''User''

'

)

Order by SamAccountName""
   

- Advertisement -