Having a problem getting a script to work when using an Array to feed information to a Function.
I have modified Alex Heitz's ADSearch() function to get specific information.

The first script works fine, but the second one gives me the IDispatch Pointers error.

homemdb is an AD attribute indicating the user's Exchange mailstore. I am
trying to get the homemdb and a partial on the servername where the
homemdb is located.

What am I doing wrong?

***********************************************

;1st script - this one works, but it is not practical for hundreds of names
Code:
break ON
$test1="abernade"
$test2="dbullock"

$str=""
$server=""
adsearch($test1)
? $str
? $server

$str=""
$server=""
adsearch($test2)
? $str
? $server

Function ADSearch($ADAccountName)
Dim $AdoCon
dim $AdoCommand
dim $Recordset
dim $Filter
dim $homemdb
dim $store
if len($ADAccountName)>0 
      $filter=" where samAccountName='"+$ADAccountName+"' "
      $AdoCon = CreateObject("ADODB.Connection")
      $AdoCon.Provider = "ADsDSOObject"
      ; Current credentials are used, as username and password aren't specified
      $AdoCon.Open("Active Directory Provider")
      ; Create ADO command object for the connection.
      $AdoCommand = CreateObject("ADODB.Command")
      $AdoCommand.ActiveConnection = $AdoCon
      $AdoCommand.CommandText ="Select homemdb from 'LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext")+"' "+$filter
      ; Execute the query.
      $Recordset = $AdoCommand.Execute
      $homeMDB=split($recordset.fields("homemdb"),",")  ;This is the line where I get the IDispatch Pointers error
      $store=split($homemdb[0],"=")
      $str=$store[1]
      $server=right($homemdb[3],4)
Else
      Exit
endif
Endfunction
 

************************************************************

;2nd script - this one fails
Code:
break ON
dim $test[5]
$test[1]="abernade" ;I don't normally create arrays this way, but for simplicity
$test[2]="dbullock"

for $x=1 to 2
   $str=""
   $server=""
   adsearch($test[$x])
   ? $str
   ? $server
next

Function ADSearch($ADAccountName)
Dim $AdoCon
dim $AdoCommand
dim $Recordset
dim $Filter
dim $homemdb
dim $store
if len($ADAccountName)>0 
      $filter=" where samAccountName='"+$ADAccountName+"' "
      $AdoCon = CreateObject("ADODB.Connection")
      $AdoCon.Provider = "ADsDSOObject"
      ; Current credentials are used, as username and password aren't specified
      $AdoCon.Open("Active Directory Provider")
      ; Create ADO command object for the connection.
      $AdoCommand = CreateObject("ADODB.Command")
      $AdoCommand.ActiveConnection = $AdoCon
      $AdoCommand.CommandText ="Select  homemdb from 'LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext")+"' "+$filter
      ; Execute the query.
      $Recordset = $AdoCommand.Execute
      $homeMDB=split($recordset.fields("homemdb"),",")  ;This is the line where I get the IDispatch Pointers error
      $store=split($homemdb[0],"=")
      $str=$store[1]
      $server=right($homemdb[3],4)
Else
      Exit
endif
Endfunction
 


Thanks for you assistance,
Dale


Edited by Daleco (2007-01-09 05:44 AM)
_________________________
Dale