Prøv med dette: (fundet på
http://www.computerperformance.co.uk/ezine/ezine27.htm)
' MoveComputer.vbs - A very difficult script.
' VBScript to Move computers from the Accounts to the Payroll OU
' Author Guy Thomas
http://computerperformance.co.uk/' Version 3.2 - April 25th 2004
' -----------------------------------------------------------------'
Option Explicit
Dim objConnection, objCommand, objRecordSet, objNewOU, objMoveComputer
Dim strComputer, strInitial, strSourceOU, strDestinationOU
Dim intCounter
' This is a tricky section. Makes a link to active directory
Const ADS_SCOPE_SUBTREE = 2
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 (not Users) in the Accounts OU
' NB Change the
LDAP://ou.... to reflect your domain.
objCommand.CommandText = _
"Select Name, Location from '
LDAP://OU=Accounts,dc=cp,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
' Treats the 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=Accounts,DC=cp,DC=com"
strDestinationOU = "OU=Payroll,DC=cp,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
' End of Script