用SQL server 獲取AD 數據

環境: Sql server 2008R2SP1 +Windows server 2008 R2 AD

 

1.開啓SQL 'Ad Hoc Distributed Queries',

exec sp_configure 'show advanced options',1  
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1   
reconfigure 
 
2.鏈接AD DB,
EXEC sp_addlinkedserver 'ADSI', 'Active Directory Services 2.5', 
'ADSDSOObject', 'adsdatasource'
GO

3.用DC的IP查詢

SELECT * FROM OpenQuery(ADSI, 'SELECT sAMAccountName FROM ''LDAP://192.168.xx.xx/OU=HR,OU=Usertest,DC=test,DC=COM,DC=CN'' WHERE objectCategory=''user'' ' )

 

 

參考:

http://msdn.microsoft.com/ZH-CN/library/windows/desktop/aa772380(v=vs.85).aspx

http://zh.wikipedia.org/wiki/Active_Directory_Service_Interface

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章