通过数据库访问AD

/*
直接通过SQL Query 方式进行访问。但前提必须在SQL Server 配置Ad Hoc Distributed Queries = 1
sp_configure 'show advanced options', 1
reconfigure
sp_configure 'Ad Hoc Distributed Queries', 1
reconfigure
*/
例子:
SELECT newid(), SamAccountName,Company,department,displayName,mail,Manager,'d2c6f186-861f-4216-81fe-4258df95658d',
getdate(),newid(),1,getdate(),null,'PORTAL',getdate(),'d2c6f186-861f-4216-81fe-4258df95658d'
FROM OPENROWSET(
'AdsDsoObject'
,'User ID=bppc\xunyi3;Password=121;ADSI Flag=0x11'
,'SELECT SamAccountName, DistinguishedName, employeeID, displayName, Company ,Manager,
department, telephoneNumber, mail, givenName,SN
FROM ''LDAP://bppcgzs2.bppc.ad/DC=bppc,DC=ad''
WHERE objectCategory = ''Person'' AND objectClass= ''user''
AND (sAMAccountName = ''SS*'')
AND userAccountControl <> 514 AND userAccountControl <> 66050
order by EmployeeID
')

 

你可能感兴趣的:(数据库,ad)