Page 1 of 1 1
Topic Options
#91863 - 2003-03-31 02:48 PM MoveHere ADSI problem
profp62 Offline
Fresh Scripter

Registered: 2003-01-26
Posts: 9
I must be stupid. What is wrong with this code ?
I think the syntax should be correct !?

;======================================================
;
; function Move_PC
;
; move workstation to $targetOU
;
; Input: $target_OU
;
;======================================================

Function Move_PC ($target_OU)

Dim $objRootDSE
Dim $LDAPSourcePC
Dim $LDAPTargetOU ,$LDAPTargetPC
Dim $objSourcePC, $objTargetOU
Dim $objMovePC

$objRootDSE = GetObject("LDAP://rootDSE").Get("defaultNamingContext")

$LDAPSourcePC = "LDAP://cn=" + $computer + ",cn=Computers," + $objRootDSE
$LDAPTargetOU = "LDAP://" + $target_OU + "," + $objRootDSE
$LDAPTargetPC = "cn=" + $computer

$objSourcePC = GetObject($LDAPSourcePC)
$objTargetOU = GetObject($LDAPTargetOU)

$objMovePC = $objTargetOU.MoveHere ($objSourcePC.ADsPath,$LDAPTargetPC) ; ERROR : expected expression!

EndFunction

Top
#91864 - 2003-03-31 05:49 PM Re: MoveHere ADSI problem
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Put some error codes into the UDF and check whether the object is actually created successfully.
code:
$objRootDSE = GetObject("LDAP://rootDSE").Get("defaultNamingContext")
? 'Error = '+@ERROR+' - '+@SERROR

_________________________
There are two types of vessels, submarines and targets.

Top
#91865 - 2003-03-31 06:13 PM Re: MoveHere ADSI problem
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
in the following line:

quote:
$LDAPSourcePC = "LDAP://cn=" + $computer + ",cn=Computers," + $objRootDSE

isn't $objRootDSE on OBJECT and not text?
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#91866 - 2003-03-31 06:25 PM Re: MoveHere ADSI problem
profp62 Offline
Fresh Scripter

Registered: 2003-01-26
Posts: 9
Thanks for reply.
To the line
$objMovePC = $objTargetOU.MoveHere ($objSourcePC.ADsPath,$LDAPTargetPC) ; ERROR : expected expression!
is all correct - all objects created successfully
(checked per debug)
It seems to be an syntax error ?!

---> ERROR : expected expression! <---

Top
#91867 - 2003-03-31 06:38 PM Re: MoveHere ADSI problem
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Did you check for error codes after each line? The DEBUG ON has nothing to do with setting the @ERROR macro.

[ 01. April 2003, 16:53: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#91868 - 2003-04-01 09:27 AM Re: MoveHere ADSI problem
profp62 Offline
Fresh Scripter

Registered: 2003-01-26
Posts: 9
If i write "checked per debug" i mean a tested always some properties of returned object, but for sure i tested with error codes to - no problem.
But script ends with this

ERROR : expected expression!
Script: D:\sources\scripts\admove\admove.kix
Line : 71

line 71 is this Movehere

Top
#91869 - 2003-04-01 03:22 PM Re: MoveHere ADSI problem
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
trying changing:

$objMovePC = $objTargetOU.MoveHere ($objSourcePC.ADsPath,$LDAPTargetPC)

to

$x = $objSourcePC.ADsPath
$objMovePC = $objTargetOU.MoveHere ($x,$LDAPTargetPC)
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#91870 - 2003-04-01 03:48 PM Re: MoveHere ADSI problem
profp62 Offline
Fresh Scripter

Registered: 2003-01-26
Posts: 9
The same error
ERROR : expected expression!

Top
#91871 - 2003-04-01 04:09 PM Re: MoveHere ADSI problem
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
where does $computer get a value?

$LDAPTargetPC = "cn=" + $computer
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#91872 - 2003-04-01 06:19 PM Re: MoveHere ADSI problem
profp62 Offline
Fresh Scripter

Registered: 2003-01-26
Posts: 9
Per Global variable.
It is possible that someone try this code on his/her system ?

I made a little changes to the code ..

;=========================================================
;
; function Move_PC
;
; move $computer from default Container to $target_OU
;
; Input: $computer,$target_OU ("cn=xxxxx,cn=yyyyy,..)
;
;=========================================================

Function Move_PC ($computer,$target_OU)

Dim $LDAPRootDSE
Dim $LDAPSourcePC
Dim $LDAPTargetOU ,$LDAPTargetPC
Dim $objSourcePC, $objTargetOU
Dim $objMovePC
Dim $Return_code

$LDAPRootDSE = GetObject("LDAP://rootDSE").Get("defaultNamingContext")

$Return_code = @ERROR
; If $Return_code <> 0
; Gosub COM_Error($Return_code)
; EndIf

$LDAPSourcePC = "LDAP://cn=" + $computer + ",cn=Computers," + $LDAPRootDSE
$LDAPTargetOU = "LDAP://" + $target_OU + "," + $LDAPRootDSE
$LDAPTargetPC = "cn=" + $computer

$objSourcePC = GetObject($LDAPSourcePC)

$Return_code = @ERROR
; If $Return_code <> 0
; Gosub COM_Error($Return_code)
; EndIf

$objMovePC = $objTargetOU.MoveHere($objSourcePC.ADsPath,$LDAPTargetPC)

$Return_code = @ERROR
; If $Return_code <> 0
; Gosub COM_Error($Return_code)
; EndIf

$LDAPRootDSE = 0
$objSourcePC = 0
$objTargetOU = 0

EndFunction

Top
#91873 - 2003-04-01 06:48 PM Re: MoveHere ADSI problem
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Generally that error results from trying to make and assignment to a variable with nothing on the right side of the equal sign.

In my Perl program that uses the ".MoveHere" method I do not assign anything to a variable when using it.

Try not using "$objMovePC = " with the statement in case the movehere method is not returning anything to be assignd to $objMovePC.

Make you statement just:
$objTargetOU.MoveHere ($objSourcePC.ADsPath,$LDAPTargetPC)

[ 01. April 2003, 18:48: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#91874 - 2003-04-02 09:21 AM Re: MoveHere ADSI problem
profp62 Offline
Fresh Scripter

Registered: 2003-01-26
Posts: 9
>Make you statement just:
>$objTargetOU.MoveHere ($objSourcePC.ADsPath,$LDAPTargetPC)

I tried it before and now one more time, the same result. Maybe i rewrite it in vbscript ...

Top
#91875 - 2003-04-02 11:27 AM Re: MoveHere ADSI problem
profp62 Offline
Fresh Scripter

Registered: 2003-01-26
Posts: 9
I'm STUPID,STUPID,STUPID
I missed

$objTargetOU = GetObject($LDAPTargetOU)

Thanks to all help

Top
#91876 - 2003-04-02 04:29 PM Re: MoveHere ADSI problem
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Sorry for the 'STUPID' revelation, I always hate that too. [Big Grin] Glad to hear it's working now.
_________________________
There are two types of vessels, submarines and targets.

Top
#91877 - 2003-04-06 08:22 PM Re: MoveHere ADSI problem
profp62 Offline
Fresh Scripter

Registered: 2003-01-26
Posts: 9
I need one more time help. The script was working now, BUT i need to run it in workstation local administrator context. So i rewrote it to use alternate credentials, but it don't function at all. I use $bind_name in syntax DOMAIN\DOMAIN_USER. If i am logged on as this user all is working right, but if i am logged on as local administrator, the lines
$objRootDSE = $objNameSpace.OpenDSObject($dnName, $bind_user, $bind_pwd, $auth_flag)
returns an error. What's wrong ?Thanks.

;=========================================================
;
; function Move_PC
;
; move $computer from default Container to $target_OU
;
; Input: $computer
; $target_OU ("OU=yyy,OU=xxx,..)
; $bind_user - optional
; $bind_pwd - optional
;
;=========================================================

Function Move_PC ($computer,$target_OU, optional $bind_user, optional $bind_pwd)

Dim $LDAPRootDSE
Dim $LDAPSourcePC
Dim $LDAPTargetOU ,$LDAPTargetPC
Dim $objSourcePC, $objTargetOU
Dim $objMovePC
Dim $objNameSpace
Dim $objRootDSE
Dim $dnName
Dim $Return_code
Dim $dummy

$ADS_SECURE_AUTHENTICATION = 1
$ADS_NO_AUTHENTICATION = 10

$auth_flag = $ADS_SECURE_AUTHENTICATION
; $auth_flag = $ADS_NO_AUTHENTICATION

If $bind_user <> ""
$objNameSpace = GetObject("LDAP:")

$Return_code = @ERROR

If $Return_code <> 0
$dummy = Send_server_COM_Error($Return_code)
EndIf
EndIf

$dnName = "LDAP://rootDSE"

If $bind_user <> ""
$objRootDSE = $objNameSpace.OpenDSObject($dnName, $bind_user, $bind_pwd, $auth_flag)
Else
$objRootDSE = GetObject($dnName)
EndIf

$Return_code = @ERROR

If $Return_code <> 0
$dummy = Send_server_COM_Error($Return_code)
EndIf

$LDAPRootDSE = $objRootDSE.Get("defaultNamingContext")

$Return_code = @ERROR

If $Return_code <> 0
$dummy = Send_server_COM_Error($Return_code)
EndIf

$LDAPSourcePC = "LDAP://CN=" + $computer + ",CN=Computers," + $LDAPRootDSE
$LDAPTargetOU = "LDAP://" + $target_OU + "," + $LDAPRootDSE
$LDAPTargetPC = "CN=" + $computer

$dnName = $LDAPSourcePC

If $bind_user <> ""
$objSourcePC = $objNameSpace.OpenDSObject($dnName, $bind_user, $bind_pwd, $auth_flag)
Else
$objSourcePC = GetObject($dnName)
EndIf

$Return_code = @ERROR

If $Return_code <> 0
$dummy = Send_server_COM_Error($Return_code)
EndIf

$dnName = $LDAPTargetOU

If $bind_user <> ""
$objTargetOU = $objNameSpace.OpenDSObject($dnName, $bind_user, $bind_pwd, $auth_flag)
Else
$objTargetOU = GetObject($dnName)
EndIf

$Return_code = @ERROR

If $Return_code <> 0
$dummy = Send_server_COM_Error($Return_code)
EndIf

$objMovePC = $objTargetOU.MoveHere($objSourcePC.ADsPath,$LDAPTargetPC)

$Return_code = @ERROR

If $Return_code <> 0
$dummy = Send_server_COM_Error($Return_code)
EndIf

$LDAPRootDSE = 0
$objSourcePC = 0
$objTargetOU = 0

EndFunction

Top
#91878 - 2003-04-07 06:03 PM Re: MoveHere ADSI problem
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You cannot authenticate to the same computer as a different user. Read the FAQ Forum, it explains how to run a script under administrative context.
_________________________
There are two types of vessels, submarines and targets.

Top
#91879 - 2003-04-08 08:42 AM Re: MoveHere ADSI problem
profp62 Offline
Fresh Scripter

Registered: 2003-01-26
Posts: 9
To sealeopard : Yes, this is the possible way, BUT why i am authenticated to the same computer as a different user ? What computer you mean ?
On local computer i am authenticated as local administrator a to the domain controller i like to be authenticated as domain user domain\domain_user, so where is the problem ?
Thanks

Top
#91880 - 2003-04-08 04:26 PM Re: MoveHere ADSI problem
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
quote:
The script was working now, BUT i need to run it in workstation local administrator context. So i rewrote it to use alternate credentials, but it don't function at all
sounds like you run the script as User A but try to authenticate against the same computer as User B in order to gain local admin rights.

See also the FnWMIAuthenticate() UDF and the 'How to install applications as an admin' FAQ in the FAQ Forum.
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


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

Who's Online
1 registered (Allen) and 581 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.098 seconds in which 0.033 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