简体   繁体   中英

LDAP connection to AD using OPENQUERY SQL Server 2008 R2

I have a query (below) that uses ldap connection to retrieve AD related info. However, the issue is this query provide all of the employees. I am only looking for current employees. I was told to use following information to pull "Active only" employees:

OU=CompanyName Users,DC=CompanyName,DC=local

I tried to modify below select statement to add OU related information, but query keeps failing. Anyone know how to convert above string into a proper ldap location?

SELECT  
*
FROM OPENQUERY( ADLink, 
'
SELECT 
   employeeNumber,
   name
FROM ''LDAP://ldap.CompanyName.local/DC=CompanyName;DC=local''
WHERE objectClass = ''user'' 
  AND objectCategory = ''Person''   
ORDER BY title asc
') A

There is an accountExpires attribute that you could probably filter on.

where accountExpires > 0

Just add accountExpires to your select list before you add it to the where clause to see the value returned. It should be the same format as your server.

I think this is not correct FROM ''LDAP://ldap.CompanyName.local/DC=CompanyName;DC=local''

Try: FROM ''LDAP://OU="Organization Unit", DC="CompanyName",DC=com''

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM