Image

Image

Search This Blog

Saturday, February 02, 2013

Move Local Computer to a different OU

On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Set WshNetwork = WScript.CreateObject("WScript.Network")
set objOU = GetObject(LDAP://ou=localComputers,ou=SOME_OU,dc=domain,dc=local)
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = _"SELECT ADsPath FROM 'LDAP://dc=domain,dc=local' WHERE objectCategory='computer' " & _"AND Name='" & wshNetwork.ComputerName & "'"

'Wscript.Echo " " & wshNetwork.ComputerName
Set objRecordSet = objCommand.Execute objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strADsPath = objRecordSet.Fields("ADsPath").Value objOU.MoveHere strADsPath, vbNullString
objRecordSet.MoveNext
Loop

No comments:

Post a Comment

Blog Archive