xyzjr 发表于 2018-10-17 11:52:42

用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


页: [1]
查看完整版本: 用SQL server 获取AD 数据