Active Directory Groups with SQL Server 2005

Ok, so I already have an existing Active Directory connection on my server. I know the active directory query is working. What I want to do is query for all ou and / or groups in the active directory and also be able to find users belonging to those groups / ous.

this is the current query, which is just pulling in user information (or part of a stored procedure configured to pull all users):

SELECT
    userAccountControl,
    DisplayName AS [NAME],
    givenName AS FIRSTNAME,
    middleName, 
    sn AS LASTNAME,
    employeeID AS EMPID,
    telephoneNumber AS EXT,
    Title, 
    Department AS DEPT,
    Division,
    sAMAccountName AS UserName,
    mail AS Email,
    homeDirectory AS HomeDir,
    userPrincipalName AS LOGON,
    manager
FROM         OPENQUERY(ADSI, 
                      '
 select
     userAccountControl,
     DisplayName,
     givenName,
     middleName,
     sn,
     employeeID,
     telephoneNumber,
     Title,
     Department,
     Division,
     sAMAccountName,
     mail,
     homeDirectory,
     userPrincipalName,
     manager
 from ''LDAP://name''
 where sn > ''a''
    and sn <''h''
 order by DisplayName
 ')
AS derivedtbl_1

      

0


source to share


1 answer


Did you know that you cannot query for more objects than the AD server is ready to return in one response?

The ADSI SQL Provider does not support paging results. The AD server is usually configured to return only the first 1000 results.



If you are querying nearly all AD objects at once, you are likely to hit this limit.

Can you elaborate on what you are trying to achieve?

+1


source







All Articles