sqlsql-servergal

How to query the GAL using SQL


I am looking for code to query the Global Address List (GAL) to obtain contacts email. I'm able to do this using VBA code. However, I was wondering if it's possible to do the same using SQL code. Also, I thinking about using SSIS package to pull over the data as well.


Solution

  • It may be something similar to:

    SELECT sAMAccountName, name, mail AS email
    FROM OPENQUERY(ADSI, 'SELECT sAMAccountName, name, mail FROM 
        ''LDAP://myServer/OU=myOU,DC=myDC1,DC=myDC2'' 
        WHERE objectCategory=''person'' AND objectClass = ''user'' '
    )