VBScript LDAP : Is there a way to query for physicalDeliveryOfficeName using the email address in Active Directory?

标签 vbscript active-directory ldap

我正在尝试使用 VBScript连接拉physicalDeliveryOfficeName Active Directory 中的属性通过提供电子邮件地址。

我知道如何使用如下通用名称来执行此操作:

Set MyUser = GetObject ("LDAP://cn=" & uname & ",ou=" & strname & ",DC=bobdom,DC=net")

但是,只有电子邮件地址可用。这该怎么做?我什至试过
Set MyUser = GetObject ("LDAP://mail=" & uname & ",ou=" & strname & ",DC=bobdom,DC=net")

这不起作用。

最佳答案

我最终写了以下内容:

Function getOffice (strname, uname) 

strEmail = uname
WScript.Echo "email: " & strEmail 
Dim objRoot : Set objRoot = GetObject("LDAP://RootDSE")
Dim objDomain : Set objDomain = GetObject("LDAP://" & objRoot.Get("defaultNamingContext"))
Dim cn : Set cn = CreateObject("ADODB.Connection")
Dim cmd : Set cmd = CreateObject("ADODB.Command")
cn.Provider = "ADsDSOObject"
cn.Open "Active Directory Provider"
Set cmd.ActiveConnection = cn

cmd.CommandText = "SELECT physicalDeliveryOfficeName FROM '" & objDomain.ADsPath & "' WHERE mail='" & strEmail & "'"
cmd.Properties("Page Size") = 1
cmd.Properties("Timeout") = 300
cmd.Properties("Searchscope") = ADS_SCOPE_SUBTREE

Dim objRS : Set objRS = cmd.Execute
    If IsNull(objRS.Fields(0)) = TRUE Then 
        getOffice = "BLANK"
    Else 
    getOffice = objRS.Fields(0)
    WScript.Echo getOffice 
    End If 


Set objRS = Nothing
Set cmd = Nothing
Set cn = Nothing
Set objDomain = Nothing
Set objRoot = Nothing
End Function 

关于VBScript LDAP : Is there a way to query for physicalDeliveryOfficeName using the email address in Active Directory?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/282627/

相关文章:

jquery - 经典的Asp持久上传和Jquery Ajax

asp.net - 事件目录开发环境

ansible - 如何从 ansible 任务将成员添加到 LDAP 组

vbscript - 作为计划任务运行脚本时"Path not found"

sql - 选择除 IDENTITY 列之外的所有列

javascript - 经典 ASP 查询字符串变量既可以设置也可以取消设置

Azure AD 用户管理委派

active-directory - 为什么我从我的 LDAP 属性中得到 'System.__ComObject'?

ldap - ldap中cn和ou的区别

java - 如何通过基于 TLS 的 LDAP 对 Active Directory 进行身份验证?