
Working from command line, but NOT in an ASP page. Why?
The main problem is the ASP page can not correctly
retrieve multi-value attribute (memberOf) from Exchange
Server. (Single-value attribute works fine, see code
below.)
The following is ASP code (not working) and identical .vbs
code (working from command line.)
ASP Code (not working)
================================================
<%
Const ADS_SCOPE_SUBTREE=2
exchServer = "exchangServerName"
Set con = CreateObject("ADODB.Connection")
Set Com = CreateObject("ADODB.Command")
'Open a Connection object
con.Provider = "ADsDSOObject"
'------------------------------------
' Open the connection
'-------------------------------------
con.Open "Active Directory Provider"
' Create a command object on this connection
Set Com.ActiveConnection = con
'--------------------------------------------------
' set the query string
'---------------------------------------------------
adsPath = "LDAP://" & exchServer & ":389"
Set oADs = GetObject(adsPath)
Com.CommandText = "select ADsPath, uid, title,
givenName, sn, mail,
physicalDeliveryOfficeName,telephoneNumber,memberOf
from '" & adsPath & "' where mail ='" & searchAlias & "'"
'-----------------------------------------
'Set the preferences for Search
'--------------------------------------
Com.Properties("Page Size") = 100
Com.Properties("Timeout") = 30 'seconds
Com.Properties("searchscope") =
ADS_SCOPE_SUBTREE 'Define in ADS_SCOPEENUM
Com.Properties("Cache Results") = False ' do not cache
the result, it results in less memory requirements
'--------------------------------------------
'Execute the query
'--------------------------------------------
Set rs = Com.Execute
'--------------------------------------
' Navigate the record set
'----------------------------------------
If ( rs.EOF = False ) Then
Response.Write "Alias = " & rs.Fields
("UID").Value & "<br/>"
Response.Write "Member Of = "
Response.Write "TypeName(memberOf) is " & TypeName
(rs.Fields("memberOf").Value) & "<br/>"
For Each item in rs.Fields("memberOf").Value
adsPath_DL = adsPath & "/" & item
Set oDL = GetObject(adsPath_DL)
Response.Write oDL.cn
Next
End If
%>
======== END OF ASP CODE ====================
searchAlias.vbs
(Working from command line:
=================================================
Set oArgs = wscript.Arguments
if ( oArgs.Count <> 1 ) then
wscript.echo "Usage exchsrch alias"
wscript.echo "e.g cscript exchsrch.vbs andyhar"
wscript.quit(0)
end if
Const ADS_SCOPE_SUBTREE=2
searchAlia{ w y Dg? S? 0v
s = oArgs(0)
exchServer = "exchangeServerName"
Set con = CreateObject("ADODB.Connection")
Set Com = CreateObject("ADODB.Command")
'Open a Connection object
con.Provider = "ADsDSOObject"
'------------------------------------
' Open the connection
'-------------------------------------
con.Open "Active Directory Provider"
' Create a command object on this connection
Set Com.ActiveConnection = con
'--------------------------------------------------
' set the query string
'---------------------------------------------------
adsPath = "LDAP://" & exchServer & ":389"
Set oADs = GetObject(adsPath)
Com.CommandText = "select ADsPath, uid, title,
givenName, sn, mail,
physicalDeliveryOfficeName,telephoneNumber,memberOf
from '" & adsPath & "' where mail ='" & searchAlias & "'"
'-----------------------------------------
'Set the preferences for Search
'--------------------------------------
Com.Properties("Page Size") = 100
Com.Properties("Timeout") = 30 'seconds
Com.Properties("searchscope") =
ADS_SCOPE_SUBTREE 'Define in ADS_SCOPEENUM
Com.Properties("Cache Results") = False ' do not cache
the result, it results in less memory requirements
'--------------------------------------------
'Execute the query
'--------------------------------------------
Set rs = Com.Execute
'--------------------------------------
' Navigate the record set
'----------------------------------------
If ( rs.EOF = False ) Then
wscript.echo "Alias = " & rs.Fields("UID").Value
wscript.echo "Name = " & rs.Fields
("givenName").Value & " " & rs.Fields("sn")
wscript.echo "Title = " & rs.Fields
("Title").Value
wscript.echo "Office = " & rs.Fields
("physicalDeliveryOfficeName").Value
wscript.echo "Telephone = " & rs.Fields
("telephoneNumber").Value
wscript.echo "Member Of = "
wscript.echo "TypeName(memberOf) is " & TypeName
(rs.Fields("memberOf").Value)
wscript.echo "TypeName(memberOf) is " & rs.Fields
("memberOf").Type
For Each item in rs.Fields("memberOf").Value
adsPath_DL = adsPath & "/" & item
Set oDL = GetObject(adsPath_DL)
wscript.echo oDL.cn
Next
End If
============ END OF searchAlias.vbs ==========
Any help would be greatly appreciated.
Dafang