OrionCookies
Programmer
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.
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.