且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从SQL Server 2005查询Active Directory

更新时间:2023-02-02 22:54:14

pretty的一般性问题,但这里有一些指点。

Pretty general question but here are some pointers.

您需要链接的服务器创建的SQL Server指向ADSI上(Active Directory服务接口),这样的事情会做到这一点。

You need a linked server creating on the SQL Server that points to ADSI (Active Directory Service Interface) something like this will do it.

EXEC sp_addlinkedserver 'ADSI', 'Active Directory Services 2.5', 'ADSDSOObject', 'adsdatasource'

然后你可以使用查询以下排序。

Then you can use the following sort of query.


SELECT *
FROM OPENQUERY(ADSI, 'SELECT sAMAccountName
FROM ''LDAP://DC=MyDC,DC=com,DC=uk''
WHERE objectCategory = ''Person''
AND objectClass = ''user'')

您需要设置LDAP://适当的线路(问你的AD管理员的详细信息),并注意分发即席查询使用OPENQUERY默认情况下在SQL Server中禁用。一旦你有以上,虽然它应该是pretty的易谷歌的任何特别的变化。

You'll need to set the LDAP:// line appropriately (ask your AD admin for the details) and be aware that distributed adhoc queries using OpenQuery are disabled by default in SQL Server. Once you have the above though it should be pretty easy to google for any particular variations.