#198575 - 2010-05-10 04:39 PM
IDispatch pointers not allowed in expressions!
|
5861king
Fresh Scripter
Registered: 2006-09-28
Posts: 48
Loc: UK
|
Hey people got a small problem with my script. I'm trying to query an account name, first of all it querires an oracle database then it should query the active directory. the problem is i get an error message "IDispatch pointers not allowed in expressions!"
I think the problem is that i'm useing periods in a varible. any advice on how to resolve this issue
Function fn_testAD()
Dim $cn, $cmd, $rs, $cnstring, $cmdtext, $selectedProperties, $propertynames, $oCn, $oCmd, $oRS, $i
$cnstring = 'Provider=MSDAORA;Password=password;User ID=user;Data Source=source;Persist Security Info=True;'
$cmdtext = "SELECT DISTINCT PEOPLE.PERSON_CODE, PEOPLE.FORENAME, PEOPLE.SURNAME, PEOPLE_UNITS.UNIT_INSTANCE_CODE, PEOPLE_UNITS.CALOCC_CODE FROM PEOPLE INNER Join PEOPLE_UNITS ON PEOPLE.PERSON_CODE = PEOPLE_UNITS.PERSON_CODE and PEOPLE_UNITS.UNIT_TYPE = 'R' and PEOPLE_UNITS.CALOCC_CODE = '09' and length(PEOPLE_UNITS.UNIT_INSTANCE_CODE) = '6' "
$cn = CreateObject("adodb.connection")
$cmd = CreateObject("adodb.command")
$cn.connectionstring = $cnstring
$cn.Open
$cmd.activeconnection = $cn
$cmd.commandtext = $cmdtext
$selectedProperties = "ADsPath"
$propertynames = Split($selectedProperties, ",")
$oCn = CreateObject("ADODB.Connection")
$oCmd = CreateObject("ADODB.Command")
$oCn.Provider = "ADsDSOObject"
$ = $oCn.Open("Active Directory Provider", "", "", -1)
$oCmd.ActiveConnection = $oCn
$oCmd.Properties("Page Size").Value = 1000
$oCmd.Properties("Searchscope").Value = 2 ;ADS_SCOPE_SUBTREE
$rs = CreateObject("adodb.recordset")
$rs.cursortype = 3
$rs.locktype = 3
$rs.Open($cmd)
While Not $rs.EOF And Not $rs.BOF
? "PERSON_CODE: " + $rs.Fields.Item("PERSON_CODE").Value
? "FORENAME: " + $rs.Fields.Item("FORENAME").Value
? "SURNAME: " + $rs.Fields.Item("SURNAME").Value
? "YEAR: " + $rs.Fields.Item("CALOCC_CODE").Value
? "GROUP: " + $rs.Fields.Item("UNIT_INSTANCE_CODE").Value
? " "
$Tempname = $rs.Fields.Item("PERSON_CODE").Value
? $Tempname
$oCmd.CommandText = "SELECT " + $selectedProperties + " FROM 'LDAP://student.domain.co.uk/DC=student,DC=domain,DC=co,DC=uk' WHERE objectCategory='user' and objectClass = 'user' AND sAMAccountName = '$Tempname' ORDER BY Name"
$oRS = $oCmd.Execute
; While Not $oRS.EOF
$obj = GetObject($oRS.Fields($propertynames[0]))
? "CN Name: " + + $obj.cn
? "First Name: " + $obj.givenname
? "Surname: " + $obj.sn
? "Login Name: " + $obj.sAMAccountName
? "Email: " + $obj.mail
? "Home Directory: " + $obj.homeDirectory
? " "
$Tempname = $rs.Fields.Item("PERSON_CODE").Value
? $Tempname
Sleep 2
$rs.MoveNext
; Loop
$rs.Close
$cn.Close
EndFunction
it fails on this line.
$obj = GetObject($oRS.Fields($propertynames[0]))
However If I remove the varible $Tempname in the active directory and change it to a static name it works
Any help much appreciated.
Thanks
Glyn
Edited by 5861king (2010-05-10 04:41 PM)
|
|
Top
|
|
|
|
#198578 - 2010-05-10 05:22 PM
Re: IDispatch pointers not allowed in expressions!
[Re: Richard H.]
|
5861king
Fresh Scripter
Registered: 2006-09-28
Posts: 48
Loc: UK
|
Use VarTypeName() to check the data type of variables on the failing line. The "IDispatch..." error normally means that you are using a complex data type (such as an object or array) where a simple data type (such as a string) is expected.
This can catch you out for example when (say) an AD object property is usually a simple string, but can sometimes be an an array when multiple values are returned.
When running the vartype it comes back as a decimal does this help?
Glyn
@Mart
I tried the ubound but it came back with no results. e.g. empty
Edited by 5861king (2010-05-10 05:33 PM)
|
|
Top
|
|
|
|
#198582 - 2010-05-11 11:22 AM
Re: IDispatch pointers not allowed in expressions!
[Re: Richard H.]
|
5861king
Fresh Scripter
Registered: 2006-09-28
Posts: 48
Loc: UK
|
Hi Richard H.
I done the VarTypeName() on $tempname i am assuming thats correct. I am also the $tempname is workingas i'm running this bit of code.
$Tempname = $rs.Fields.Item("PERSON_CODE").Value
? $Tempname
from this bit of code a number is returned which it does for example when running ? $tempname it reports back on the console as
9847430
therefore I would assusme useing $tempname would work in the active directory as show below
$oCmd.CommandText = "SELECT " + $selectedProperties + " FROM 'LDAP://student.domain.co.uk/DC=student,DC=domain,DC=co,DC=uk' WHERE objectCategory='user' and objectClass = 'user' AND sAMAccountName = '9847430' ORDER BY Name"
now if change the code to the folowing it works
$oCmd.CommandText = "SELECT " + $selectedProperties + " FROM 'LDAP://student.domain.co.uk/DC=student,DC=domain,DC=co,DC=uk' WHERE objectCategory='user' and objectClass = 'user' AND sAMAccountName = '$Tempname' ORDER BY Name"
so I'm not to sure what is going wrong?
Edited by 5861king (2010-05-11 11:25 AM)
|
|
Top
|
|
|
|
#198584 - 2010-05-11 11:50 AM
Re: IDispatch pointers not allowed in expressions!
[Re: 5861king]
|
5861king
Fresh Scripter
Registered: 2006-09-28
Posts: 48
Loc: UK
|
Little bit of an update
If i create a new varible and call it $tempname2 then i manualy insert a number for example
$tempname2 = '48394823923'
this makes the script work so the problem is that the
so this bit code does not work.
$Tempname = $rs.Fields.Item("PERSON_CODE").Value
? $Tempname
however why does the varible work when asking it by useing the ?
Edited by 5861king (2010-05-11 12:01 PM)
|
|
Top
|
|
|
|
#198586 - 2010-05-11 02:46 PM
Re: IDispatch pointers not allowed in expressions!
[Re: 5861king]
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
It could be as simple as the variable type.
Try this:
$Tempname = CStr($rs.Fields.Item("PERSON_CODE").Value)
The CStr() will convert the value to a string, the same as assigning an explicit value in single quotes.
|
|
Top
|
|
|
|
#198587 - 2010-05-11 03:08 PM
Re: IDispatch pointers not allowed in expressions!
[Re: Richard H.]
|
5861king
Fresh Scripter
Registered: 2006-09-28
Posts: 48
Loc: UK
|
Thats brilliant,
It worked thank you very much Richard. 
So i take it the varible i was useing was not in a string format is that correct?
|
|
Top
|
|
|
|
#198590 - 2010-05-11 04:46 PM
Re: IDispatch pointers not allowed in expressions!
[Re: Richard H.]
|
5861king
Fresh Scripter
Registered: 2006-09-28
Posts: 48
Loc: UK
|
Thank you for all the Help & Explanation
Glyn
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 1334 anonymous users online.
|
|
|