使用VBScript读取Exchange

时间:2009-09-10 18:33:03

标签: coldfusion vbscript active-directory exchange-server

我在ColdFusion中编写了这段代码来从Exchange读取数据,我想知道是否有人可以帮助我使用Visual Basic脚本编写代码:

<cfldap
  server="insert_my_server_name_here"
  username="zzz\zzzzzz"
  password="xxxx"
  port = "123"
  action = "query"
  name = "data"
  attributes = "company"
  filter = "(&(objectclass=group))"
  returnAsBinary = "objectSID"
>

我到目前为止,但它返回一个未找到的表错误:

Dim UserID
UserID = "my_user_ID"

Set objConn = CreateObject("ADODB.Connection")
objConn.Provider = "ADsDSOObject"
objConn.Open "Active Directory Provider"

Dim Base, Filter, Attr, Level, Server
Server = "insert_my_server_name_here"

Base = "<LDAP://" & Server & "/DC=dot,DC=com>;"
Filter = "(&(objectClass=user)(objectCategory=person)(samAccountName=" & UserID & "));" 
Attr = "distinguishedName;"
Level = "SubTree"

Set RecordSet = objConn.Execute(Base & Filter & Attr & Level)

RecordSet.MoveFirst
While Not RecordSet.EOF
  Wscript.echo RecordSet.Fields(0).Value
  RecordSet.MoveNext
Wend

1 个答案:

答案 0 :(得分:1)

您发布的代码很好。

我认为您必须在LDAP查询字符串中对您的域的引用不正确。您正在使用变量“服务器”来提供域控制器的名称,这很好(但通常是不必要的),但您是否正在更改“DC = dot,DC = com”以反映您的域名? EG如果您的域名是My.Domain,则应为'DC = My,DC = Domain'