使用OPENQUERY来连接到Active Directory [英] using openquery to connection to Active directory

查看:186
本文介绍了使用OPENQUERY来连接到Active Directory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code连接到我的活动目录,然后将用户在某个组。由于code是它下面的工作正常,但我必须到c我想看看该部门的硬$ C $。

我想传递参数给openqueries第二个参数(第二code),但我不断收到一个错误,我知道它与我的引号的问题,任何帮助将大大AP preciated感谢

  SELECT *
从OPENQUERY(ADSI

选择
给定的名称,
SN,
sAMAccountName赋,
显示名称,
邮件,
电话号码,
移动,
physicalDeliveryOfficeName,
部门,
联赛


从'LDAP:// DC = directorysync,DC = CFC,DC = COM''
其中,objectCategory属性=''人''
和objectcla​​ss ='​​'用户''
和部门=''生产''
和DisplayName<> ''0_UW_Template_Remote''
ORDER BY显示名
')



选择 *
从OPENQUERY(ADSI

选择
给定的名称,
SN,
sAMAccountName赋,
显示名称,
邮件,
电话号码,
移动,
physicalDeliveryOfficeName,
部门,
联赛


从'LDAP:// DC = directorysync,DC = CFC,DC = COM''
其中,objectCategory属性=''人''
和objectcla​​ss ='​​'用户''
和部门='''+ @部+'''
和DisplayName<> ''0_UW_Template_Remote''
ORDER BY显示名
')
 

解决方案

您不能构建 OPENQUERY 调用中的查询,你需要建立一个查询变量然后执行它。

 声明@qry VARCHAR(8000)
设置@qry =SELECT *
从OPENQUERY(ADSI,''
    选择
    给定的名称,
    SN,
    sAMAccountName赋,
    显示名称,
    邮件,
    电话号码,
    移动,
    physicalDeliveryOfficeName,
    部门,
    联赛


    从''''LDAP:// DC = directorysync,DC = CFC,DC = com的''''
    其中,objectCategory属性=''''人''''
    和objectcla​​ss ='​​'''用户''''
    和部门='''''+ @部+'''''
    和DisplayName<> ''''0_UW_Template_Remote''''
    ORDER BY显示名
'')'

EXEC(@qry)
 

I have the following code to connect to my active directory and then pull users in a certain group. As the code is below it works fine, however I have to hard code the department I want to look in.

I am trying to pass a parameter to the openqueries second parameter (second code) but I keep getting an error, I know its a problem with my quotation marks, any help would be greatly appreciated thanks,

select *
from openquery(ADSI, '

select
givenName, 
sn, 
sAMAccountName, 
displayName,
mail, 
telephoneNumber, 
mobile, 
physicalDeliveryOfficeName, 
department, 
division


from ''LDAP://DC=directorysync,DC=cfc, DC=com'' 
where objectCategory = ''Person'' 
and objectClass = ''user''
and department = ''Production''
AND displayname <> ''0_UW_Template_Remote''
ORDER BY displayName
')



select *
from openquery(ADSI, '

select
givenName, 
sn, 
sAMAccountName, 
displayName,
mail, 
telephoneNumber, 
mobile, 
physicalDeliveryOfficeName, 
department, 
division


from ''LDAP://DC=directorysync,DC=cfc, DC=com'' 
where objectCategory = ''Person'' 
and objectClass = ''user''
and department = '''+@Department+'''
AND displayname <> ''0_UW_Template_Remote''
ORDER BY displayName
')

解决方案

You cannot construct the query within the openquery call, you'll need to build the query in a variable then execute it.

declare @qry varchar(8000)
set @qry = 'select *
from openquery(ADSI, ''
    select
    givenName, 
    sn, 
    sAMAccountName, 
    displayName,
    mail, 
    telephoneNumber, 
    mobile, 
    physicalDeliveryOfficeName, 
    department, 
    division


    from ''''LDAP://DC=directorysync,DC=cfc, DC=com'''' 
    where objectCategory = ''''Person'''' 
    and objectClass = ''''user''''
    and department = '''''+@Department+'''''
    AND displayname <> ''''0_UW_Template_Remote''''
    ORDER BY displayName
'')'

exec(@qry)

这篇关于使用OPENQUERY来连接到Active Directory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆