Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Move computer from one OU to another OU

Status
Not open for further replies.

OrionCookies

Programmer
May 5, 2005
43
US
New to vbscript, but working through all small detail.
I have this script to move computers from one OU to another, and I am getting error "Move computers.vbs(33, 1) Provider: A referral was returned from the server".
here is the script:


Option Explicit
Dim objConnection, objCommand, objRecordSet, objNewOU, objMoveComputer
Dim strComputer, strInitial, strSourceOU, strDestinationOU
Dim intCounter

' Makes a link to active directory
Const ADS_SCOPE_SUBTREE = 4
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objCOmmand.ActiveConnection = objConnection

' Selects all the computer objects in the BuildWKS OU
objCommand.CommandText = "Select name, Location from 'LDAP://OU=buildwks,OU=administration,OU=IT,dc=na,dc=corp,dc=gmacrfc,dc=com'"_
& "where objectClass='computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False

' computer objects as a set of record cards
Set objRecordSet = objCommand.Execute
objRecordSet.Movefirst
' Get all the records
Do Until objRecordSet.EOF
strComputer = objRecordSet.Fields("Name").Value
strComputer = "CN="& strComputer
intCounter = intCounter +1
Wscript.Echo "Computer Name: " & strComputer

' N.B. change the next two lines to OUs in YOUR domain.
strSourceOU = "OU=buildwks,OU=administration,OU=IT,dc=na,dc=corp,dc=gmacrfc,dc=com"
strDestinationOU = "OU=MSPA,OU=US,OU=Test_IT,OU=IT,DC=na,DC=corp,DC=gmacrfc,DC=com"

Set objNewOU = GetObject("LDAP://" & strDestinationOU)
Set objMoveComputer = objNewOU.MoveHere _
("LDAP://" & strComputer & strSourceOU, strComputer)

objRecordSet.MoveNext

Loop

Wscript.Echo intCounter & " Computers moved to " & strDestinationOU

WScript.Quit


Now the line 33 is
objRecordSet.Movefirst
getting error message.

any help would be appreciated.

thanks in advance.
 
>[tt]Set objMoveComputer = objNewOU.MoveHere _
("LDAP://" & strComputer & strSourceOU, strComputer)
Set objMoveComputer = objNewOU.MoveHere _
("LDAP://" & strComputer [red]& ","[/red] & strSourceOU, strComputer)[/tt]
 
Thanks for reply, still I am getting on line the line 33 which is
>objRecordSet.Movefirst
 
>[tt]objCommand.CommandText = "Select name, Location from 'LDAP://OU=buildwks,OU=administration,OU=IT,dc=na,dc=corp,dc=gmacrfc,dc=com'"_
>& "where objectClass='computer'"
objCommand.CommandText = "Select name, Location from 'LDAP://OU=buildwks,OU=administration,OU=IT,dc=na,dc=corp,dc=gmacrfc,dc=com'"_
& "[COLOR=red yellow] [/color]where objectClass='computer'"[/tt]
 
Again, really appreciate for your reply.


Same line error
>objRecordSet.Movefirst
 
There is nothing wrong with that line.
 
I meant it is something else that makes the return set problematic.
 
>[tt]Const ADS_SCOPE_SUBTREE = 4
Const ADS_SCOPE_SUBTREE = [red]2[/red][/tt]
 
that's I had thought and changed it before to 2 or 3.tested, no luck...same error.

And you are right. this line is >objRecordSet.Movefirst is not the error....
 
That is a system constant with no room to experiment.

I conclude those three are genuine errors. Have you seriously tried to correct them and run the script? Else, I have nothing to offer.

- tsuji
 
Yes I had did,,,
I really appreciate all your help,,,thanks in advance.
 
How does vbscript structure look like on LDAP

My AD looks like this.(computer move from)
na.corp.gmacrfc.com (dc)
I have OU
IT -
- Administration
-BUILDWKS

Computers move to OU
IT
-TEST_IT
-US
-MSPA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top