Registered: 2006-11-16
Posts: 23
Loc: Colorado, USA
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
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
First I'd like to suggest you edit your post and put your code in the code tags (# button) so that it will be easier to read.
The other odd thing I see is it looks like you've modified the UDF to pull different information, but its not returning anything, ie the ADSearch variable is not being defined with a return value.
As for your error, You might try changing this: $homeMDB=split($recordset.fields("homemdb"),",") to (untested) $homeMDB=$recordset.fields("homemdb") $homeMDB=split($homeMDB,",")
Also, your for loop could be much easier... $test="abernade","dbullock" for each $x in $test ? $x ;do stuff next
Registered: 2006-11-16
Posts: 23
Loc: Colorado, USA
Thanks Allen
By using the loop as you indicated it seems to work. It seems in this case that you can't use the array directly in the Function call as I did in the 2nd script. I did not have to change the homemdb line. This script will be used to capture information on up to several hundred accounts using the account name. Wioth a couple more tweeks this should work nicely in the main script I'm using.
Hopefully I will not run into any more difficulty with it.
Registered: 2006-11-16
Posts: 23
Loc: Colorado, USA
I am still having difficulty with this piece of code. I have found that the function ADSearch() does not work well if the account name has a period in it, I get the IDispatch error. If the account name does not have a period in it the script below runs fine. The ADSearch function is modified slightly because I needed a different field returned.
Code:
break ON
$test1="aber.nade" ; The period in this account name causes the IDispatch error
$str=""
$server=""
adsearch($test1)
? $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 gives the error
$store=split($homemdb[0],"=")
$str=$store[1]
$server=right($homemdb[3],4)
Else
Exit
endif
Endfunction
Registered: 2006-11-16
Posts: 23
Loc: Colorado, USA
Thanks for that Witto, but the problem still remains.
If I use the account name "aber.nade" it does not work, but if the account name does not contain a period "abernade" then it works fine. The problem seems to center around the period in the account name.
Registered: 2006-11-16
Posts: 23
Loc: Colorado, USA
Allen, Thanks for the test script. I had made the changes you suggested before, but I have the same results when the logon name has a period in it. This is part of what is in the HomeMDB record:
CN=PAFB-SG7-AEN CN=PAFB-SG7 (T-Z) CN=InformationStore CN=serverML30 CN=Servers CN=First Administrative Group CN=Administrative Groups CN=AFSPC CN=Microsoft Exchange CN=Services CN=Configuration
The parts I am capturing are in RED bold. I have written this script several different ways and the results are always the same, as long as there is no period in the account name it runs fine.
The test script you wrote also runs fine if there is no period in the account name, but fails if there is one.
Your script gets the IDispatch error on the same line as I do.
Code:
$homeMDB=split($recordset.fields("homemdb"),",") ; This gives the IDispatch error
Registered: 2006-11-16
Posts: 23
Loc: Colorado, USA
It does not process for a user with the period in it. The information above is from a user with no period. BTW, your script does not fail if there is not period in the name, but is doesn't return the data I need either. The data will be different for many users and I need both pieces of information for each user.
I understand that it did not fix the error... what I am confused about is why it did not return any values. Can you add some error checking to the function?
Registered: 2006-11-16
Posts: 23
Loc: Colorado, USA
No I can't use MSN (not allowed here)
Without a period in the account name: The $Homemdb is populated correctly in each instance below
Code:
$homeMDB=split($recordset.fields("homemdb"),",")
select
case $mode="Store"
$store=split($homemdb[0],"=")
$HOMEMDB=$store[1]
case $mode="Server"
$HOMEMDB=right($homemdb[3],4)
endselect
With a period in it fails on the first line above. Do you have a suggestion on a way to error check this?
k... so that means that with a period it is not running the query correctly. The reason you are getting an error is because its trying to split something that has nothing there.