Page 1 of 1 1
Topic Options
#108808 - 2003-11-24 08:00 PM Updating current objects in AD
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Kix 4.22

Trying to update objects in AD..

PutEx yields:
Quote:


Name: -2147352571 - Type mismatch.
Cube: -2147352571 - Type mismatch.
SetInfo: -2147352571 - Type mismatch.





Put yields:
Quote:


20009]-2147352567 - COM exception error "Put" ((null) - (null)) [-2147352567/800
20009]-2147352567 - COM exception error "Put" ((null) - (null)) [-2147352567/800
80020009]-2147352567 - COM exception error "Put" ((null) - (null)) [-2147352567/





Here is the code:

Code:

?@kix
$dt=READVALUE('HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders','Desktop')
READEXCEL($dt+'\computers.xls')

FUNCTION READEXCEL($cfilename)
DIM $rc,$row,$oxl,$c
$ldaploc=',ou=Computer,ou=Accounts,ou=Company Name,ou=Companies,dc=DOMAIN,dc=COMPANY,dc=com'
$logfile='H:\USERDETAILS.CSV'
IF 0=EXIST($cfilename) ;insure the file exists
?'Excel file not found'
SLEEP 4
RETURN ;leave
ENDIF
$oxl=Createobject('Excel.application')
;Check to insure that Excel is available
IF 0<>@error ?@error ' Excel Application is not found'
SLEEP 4
RETURN
ENDIF
$rc=$oxl.workbooks.open($cfilename)
$row=1 ;Row to start at using column headings, change to 0, if needed
WHILE $oxl.cells($row,1).value<>'' ;need a value each time in column 1
$row=$row+1
IF $oxl.cells($row,1).value='' ;Once it gets to a blank row...
$oxl.quit ;quit Excel
$oxl=0 ;set the object to 0
ELSE
$computer=$oxl.cells($row,1)
?$computer
$objcomputer=GetObject('LDAP://cn='+$computer+$ldaploc)
IF @error=0
$name=$oxl.cells($row,2)
?$name
$objcomputer.put('description',cstr('COMPANY - Location - '+$name))
;@ERROR+' - '+@SERROR
$cube=$oxl.cells($row,3)
?$cube
$objcomputer.put('location',cstr('Cube in Location - '+$cube))
;?'Cube: '+@ERROR+' - '+@SERROR
$objcomputer.setinfo
;?'SetInfo: '+@ERROR+' - '+@SERROR
$objcomputer=0
ELSE ;If it cannot create a valid object
LOGGER($logfile,$computer+@crlf)
ENDIF
ENDIF
LOOP
$oxl.quit ;quit Excel
$oxl=0
ENDFUNCTION

FUNCTION LOGGER($logfile,$logdata)
DIM $n
WHILE Open(1,$logfile,5)<>0
IF $n
'.'
ELSE
? 'Please wait'
ENDIF
$n=$n+1
;IF $n=6
; EXIT(1)
;ENDIF
SLEEP 1
LOOP
$n=WriteLine(1, $logdata)
$n=Close(1)
ENDFUNCTION


Thanks,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#108809 - 2003-11-24 08:21 PM Re: Updating current objects in AD
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
PutEx requires an array vartype not a long or string.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#108810 - 2003-11-24 09:32 PM Re: Updating current objects in AD
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Howard,

Thanks for the update..

I have added in a Logging routine to log errors, but does not continue on.

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#108811 - 2003-11-24 09:54 PM Re: Updating current objects in AD
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Generally when the "Put" fails the object to which you are trying to "Put" does not exists or is the wrong data type.

Have you checked to to verify that your GetObject was a success?

Also when running a getObject to ADSI from a client computer, I found it better to include a binding target in the ADSI binding string:

$objcomputer=GetObject('LDAP://$Domain/cn='+$computer+$ldaploc)

What is this? [ IF $objcomputer=0 ] If you have a valid ADSI object it will not equal zero.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#108812 - 2003-11-24 10:32 PM Re: Updating current objects in AD
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
I have tried different ways to do this.. It does not seem to work properly..

If @error=0

If @error<>0

and so on..

I was trying to get this when it fails to continue on, but log the problematic area.

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#108813 - 2003-11-24 11:01 PM Re: Updating current objects in AD
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
"If @error=0" would be the correct coding for verifying a success of GetObject.

Have you broken down your script to verify you are getting the ADSI computer object?
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#108814 - 2003-11-24 11:34 PM Re: Updating current objects in AD
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
I think you have hit on what I need to do.. I need to look for the object first and if it does not exist, go to the next record.

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#108815 - 2003-11-24 11:54 PM Re: Updating current objects in AD
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Original code is updated.. It works fine now..

Thanks,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 1334 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.058 seconds in which 0.025 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org