Solved

Moving Computers from one OU to another OU

Posted on 2003-11-17
5
617 Views
Last Modified: 2008-01-16
Hello All
I am trying to move a computer object in AD from one OU to another ou and I keep getting the below error.  I am pulling the Ldap Path (target and destination) and the computername from a text file.  

C:\Support\movecomputer.vbs(28, 1) Microsoft VBScript runtime error: Wrong numbe
r of arguments or invalid property assignment: 'objNewOU.MoveHere'

Below is the Script
Set oCmdArgs = CreateObject("MTP.CmdArgs")

oCmdArgs.FromCollection(wscript.Arguments)
chnglist2 = oCmdArgs(0).Text
oCmdArgs.Reset
Set oStream = CreateObject("Scripting.FilesystemObject").OpenTextFile(chnglist2)
oCmdArgs.FromStream(oStream)

For ix = 0 To (oCmdArgs.Count - 1)
' Wscript.echo "Arg " & ix & ": " & oCmdArgs(ix).Text
'parses the test file and assigns variables for each value
sArray = Split(oCmdArgs(ix).Text, ";")
Computername = sArray(0)
ADSPath = sArray(1)
targetadspath = sArray(2)

'Wscript.echo targetadspath


Set objNewOU = GetObject("LDAP://" & targetadspath & "")


Set objMoveComputer = objNewOU.MoveHere("LDAP://CN=" & Computername & "," & ADSPath & ", " & """" & Computername & """")
Next
0
Comment
Question by:magsdtev
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 3

Expert Comment

by:tim_mcgue
ID: 9763886
This method takes two parameters.  See this article:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netdir/adsi/iadscontainer_movehere.asp

It looks like you want to replace your second to last line with this:

Set objMoveComputer = objNewOU.MoveHere("LDAP://CN=" & Computername & "," & ADSPath, "CN=" & Computername)

or this:
Set objMoveComputer = objNewOU.MoveHere("LDAP://CN=" & Computername & "," & ADSPath, vbNullString)
0
 

Author Comment

by:magsdtev
ID: 9771543
Tim
Thanks for the response.  I tried the above with no sucess.  After alot of research I found that the below worked

Set oCmdArgs = CreateObject("MTP.CmdArgs")

oCmdArgs.FromCollection(wscript.Arguments)
chnglist2 = oCmdArgs(0).Text
oCmdArgs.Reset
Set oStream = CreateObject("Scripting.FilesystemObject").OpenTextFile(chnglist2)
oCmdArgs.FromStream(oStream)
'Gets the text file and parses it
For ix = 0 To (oCmdArgs.Count - 1)
'      Wscript.echo "Arg " & ix & ": " & oCmdArgs(ix).Text
      'parses the test file and assigns variables for each value
      sArray = Split(oCmdArgs(ix).Text, ";")      
      Computername = sArray(0)
      srcADSPath = sArray(1)
      targetadspath = sArray(2)

Set objNewOU = GetObject("LDAP://" & targetadspath)
Set objsrcOU = GetObject("LDAP://CN=" & Computername & "," & srcADSPath)

Wscript.echo Computername

'Set objMoveComputer = objNewOU.MoveHere("LDAP://CN=" & Computername & "," & ADSPath & ", CN=" & Computername)

objNewOU.MoveHere objsrcOU.ADsPath, objsrcOU.Name

Next
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 10548568
magsdtev, an EE Moderator will handle this for you.
Moderator, my recommended disposition is:

    Refund points and save as a 0-pt PAQ.

Dan Rollins -- EE database cleanup volunteer
0
 

Accepted Solution

by:
CetusMOD earned 0 total points
ID: 10598787
PAQed, with points refunded (200)

CetusMOD
Community Support Moderator
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question