Announcement

Collapse
No announcement yet.

Script for move computer account from Computer OU to another..

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Script for move computer account from Computer OU to another..

    hi ,
    someone know script to move Computers account from the computer ou to the right one ?

    i have alot of brache offices around the world..
    when someone from the HD add computer account to the domain it automatcly move to the computers ou..

    i need a solutoion that when someone is adding computer to the domain to move to the right location in the AD.

    who can help me ?

  • #2
    Re: Script for move computer account from Computer OU to another..

    Here is a start if you want to go down the scripting route.

    Ref: http://www.microsoft.com/technet/scr.../cscad007.mspx
    Code:
    ' Verify arguments
    If Wscript.Arguments.Count = 0 or Wscript.Arguments.Count > 1 Then
    	Wscript.Echo "used like this: 'movepc.vbs COMPUTERNAME' "
    Else
    'Set variables, where to search and where to move the computer
    strSoeg = "'LDAP://dc=DOMAIN,dc=COM' WHERE objectCategory='computer' AND name=" 'LDAP path to search
    ' if you want to move users then change the objectCategory to 'user' instead
    
    strDestination = "LDAP://OU=Student_PC,OU=Software_Distribution,DC=DOMAIN,DC=COM" ' LDAP path of destination
    
    'Set computername to argument 0 (first argument)
    	strComputerName = Wscript.Arguments(0)
    	lenComp = len(strComputername) + 11
    	On Error Resume Next
    
    	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
    
    	objCommand.Properties("Page Size") = 1000
    	objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
    
    	' Search command
    	objCommand.CommandText = _
    		"SELECT ADsPath FROM  " & strSoeg & "'" & strComputerName & "'"
    	' Search
    	Set objRecordSet = objCommand.Execute
    
    	objRecordSet.MoveFirst
    	Do Until objRecordSet.EOF	
    		strADsPath = objRecordSet.Fields("ADsPath").Value
    		Set objNewOU = GetObject(strDestination)
    
    		Set objMoveComputer = objNewOU.MoveHere (strADsPath, "CN=" & strComputerName)
    		objRecordSet.MoveNext
    	Loop
    
    msgbox "Done!"
    
    end if
    
    ' Clean up
    set objNewOU = nothing
    set objMoveComputer = nothing
    set objRecordSet = nothing
    set objCommand = nothing
    set objConnection = nothing
    Caesar's cipher - 3

    ZKHQ BRX HYHQWXDOOB GHFLSKHU WKLV BRX ZLOO UHDOLVH LW ZDV D ZDVWH RI WLPH!

    SFX JNRS FC U6 MNGR

    Comment

    Working...
    X