Here is a version that sorts the results...
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*'"
$sOrderBy = "order by name"
$aResults = fnADODBQuery($aWhat,$sFrom,$sWhere,$sOrderBy)
For Each $Result in $aResults
$Result ?
Next
? "The query returned " + (UBound($aResults)+1) + " results." ?
Get $
Function fnADODBQuery($What,$From,$Where,Optional $OrderBy, 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 + $OrderBy
$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