Ok, I have reversioned my fnADODBQuery prototype again. This version will return a value or an array of values based on a search.

ADODBQuery should return results much faster than a regular LDAP query.

Let me know what you think.

Code:

;==========================================================================
;
; NAME: fnADODBQuery
;
; AUTHOR: Christopher Shilt (christopher.shilt@relizon.com)
; DATE : 7/15/2004
;
; COMMENT: Uses ADODB to retrieve information from Active Directory
;
;==========================================================================
$=SetOption("WrapAtEOL","on")

$aWhat = "Name"
$sFrom = "LDAP://DC=your,DC=domain,DC=com"
$sWhere = "objectClass = 'computer' and name = 'ATL*'"

$aResults = fnADODBQuery($aWhat,$sFrom,$sWhere)

For Each $Result in $aResults
$Result ?
Next

Get $

Function fnADODBQuery($What,$From,$Where,Optional $Scope)
Dim $objconnection, $objCommand, $objRecordSet

If NOT $Scope $Scope = 2 EndIf
If VarType($What)>8192
$sWhat=Join($What,',')
Else
$sWhat=$What
EndIf

$sQuery = "Select " + $sWhat + " from " + "'" + $From + "' where " + $Where

$objConnection = CreateObject("ADODB.Connection")
$objCommand = CreateObject("ADODB.Command")
$objConnection.Provider = "ADsDSOObject"
$objConnection.Open("Active Directory Provider")
$objCommand.ActiveConnection = $objConnection

$objCommand.CommandText = $sQuery
$objCommand.Properties("Page Size").Value = 1000
$objCommand.Properties("Timeout").Value = 30
$objCommand.Properties("Searchscope").Value = $Scope
$objCommand.Properties("Cache Results").Value = NOT 1
$objRecordSet = $objCommand.Execute
$objRecordSet.MoveFirst

If VarType($What)>8192
For Each $Field in $What
$GetValue = $GetValue + '$' + 'objRecordSet.Fields("' + $Field + '").Value,'
Next
$GetValue=Substr($GetValue,1,Len($GetValue)-1)
Else
$GetValue = '$' + 'objRecordSet.Fields("' + $What + '").Value'
EndIf

Dim $aRecords[0]
$r = 0

Do
$nul=Execute('$'+'aProperties = ' + $GetValue)
$aRecords[$r] = $aProperties
$objRecordSet.MoveNext
$r = $r + 1
ReDim Preserve $aRecords[$r]
Until $objRecordSet.EOF
ReDim Preserve $aRecords[$r-1]
$fnADODBQuery = $aRecords
EndFunction