标签:
参考:http://www.pawlowski.cz/2011/04/querying-active-directory-sql-server-t-sql/
1.建立 link server .
use master
go
EXEC sp_addlinkedserver ‘ADSI‘, ‘Active Directory Services 2.5‘, ‘ADSDSOObject‘, ‘adsdatasource‘
2.
exec sp_configure ‘show advanced options‘, 1
reconfigure with override
exec sp_configure ‘Ad Hoc Distributed Queries‘, 1
reconfigure
3.查询域帐户信息:
SELECT * FROM OpenQuery(ADSI, ‘SELECT * FROM ‘‘LDAP:// DC=huanhua,DC=test‘‘ WHERE objectCategory=‘‘user‘‘ ‘)
SELECT * FROM OpenQuery(ADSI1, ‘SELECT * FROM ‘‘LDAP://192.168.1.100/DC=huanhua,DC=test‘‘ WHERE objectCategory=‘‘user‘‘ ‘)
查询结果
实际域帐户信息:
其它:
SELECT * FROM
OpenQuery(ADSI1, ‘SELECT cn,ADsPath FROM ‘‘LDAP://192.168.1.100/DC=huanhua,DC=test‘‘ WHERE objectCategory=‘‘user‘‘ ‘)
注意:如果提示没权限,链接数据库一定要用域帐户登录。
标签:
原文地址:http://www.cnblogs.com/huaan011/p/4276108.html