How to query the GAL using SQL

443 Views Asked by At

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.

1

There are 1 best solutions below

0
Shawn On BEST ANSWER

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'' '
)