4

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

我知道如何使用如下通用名称进行操作:

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

但是,只有电子邮件地址可用。这该怎么做?我什至试过

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

那是行不通的。

4

2 回答 2

4

我最终写了以下内容:

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 
于 2008-11-21T17:43:52.483 回答
2

如果使用LDAP查询(不确定在您的情况下是否需要服务器名称):

<LDAP://SERVERNAME/DC=bobdom,DC=net>;(&(objectClass=user)(mail=mike.spencer@kenblanchard.com));

在我自己的环境中尝试一下,它看起来像这样(有一些通用化的东西):

<LDAP://SERVERNAME/DC=bobdom,DC=net>;(&(mail=email@company.com));name,mail,member,description,memberOf,userParameters,userAccountControl,whenCreated,CN;subTreeCount=1

整个批次看起来像这样(在 ASP 中;如果在 .vbs 文件中完成,您需要将其更改Server.CreateObjectCreateObject...我认为)。

Set oCon        = Server.CreateObject("ADODB.Connection")
oCon.Provider   = "ADsDSOObject"
oCon.Open "ADProvider", "ADUsername", "ADPassword"

Set oCmd        = Server.CreateObject("ADODB.Command")
Set oCmd.ActiveConnection = oCon

sQuery = "<LDAP://SERVERNAME/DC=bobdom,DC=net>;(&(mail=email@company.com));name,distinguishedName,physicalDeliveryOfficeName;subTreeCount=1>"

oCmd.CommandText = sQuery
Set ADRecordSet = oCmd.Execute

您可能需要摆弄subTreeCount.

于 2008-11-14T00:26:05.840 回答