magsdtev
asked on
Moving Computers from one OU to another OU
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.vb s(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(ws cript.Argu ments)
chnglist2 = oCmdArgs(0).Text
oCmdArgs.Reset
Set oStream = CreateObject("Scripting.Fi lesystemOb ject").Ope nTextFile( chnglist2)
oCmdArgs.FromStream(oStrea m)
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
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.vb
r of arguments or invalid property assignment: 'objNewOU.MoveHere'
Below is the Script
Set oCmdArgs = CreateObject("MTP.CmdArgs"
oCmdArgs.FromCollection(ws
chnglist2 = oCmdArgs(0).Text
oCmdArgs.Reset
Set oStream = CreateObject("Scripting.Fi
oCmdArgs.FromStream(oStrea
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://
Next
ASKER
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(ws cript.Argu ments)
chnglist2 = oCmdArgs(0).Text
oCmdArgs.Reset
Set oStream = CreateObject("Scripting.Fi lesystemOb ject").Ope nTextFile( chnglist2)
oCmdArgs.FromStream(oStrea m)
'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
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(ws
chnglist2 = oCmdArgs(0).Text
oCmdArgs.Reset
Set oStream = CreateObject("Scripting.Fi
oCmdArgs.FromStream(oStrea
'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://
objNewOU.MoveHere objsrcOU.ADsPath, objsrcOU.Name
Next
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
Moderator, my recommended disposition is:
Refund points and save as a 0-pt PAQ.
Dan Rollins -- EE database cleanup volunteer
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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://
or this:
Set objMoveComputer = objNewOU.MoveHere("LDAP://