Results 1 to 3 of 3

Thread: Script to move computers to another OU

  1. #1
    Join Date
    Jan 2006
    Posts
    115

    Script to move computers to another OU

    Is there anyone who can provide me a script which can move machines from a text file to another OU. Thanks for any help

  2. #2
    Join Date
    Jun 2006
    Posts
    623

    Re: Script to move computers to another OU

    You can check out the below script to move all the computers listed in a text file to a new OU. The script also creates and/or updates a log file with the original distinguished name of each computer:

    Code:
    on error resume next 
     
    CONST ForReading = 1 
    Const ForAppending = 8 
     
    Set oFS = CreateObject("Scripting.FileSystemObject") 
    Set oTS = oFS.OpenTextFile("oldcomputers.txt",ForReading) 
    set oLS = oFS.OpenTextFile("movecomputerlog.txt",ForAppending,True) 
    Set objRootDSE = GetObject("LDAP://RootDSE") 
    strDNSDomain = objRootDSE.Get("defaultNamingContext") 
    Set objCommand = CreateObject("ADODB.Command") 
    Set objConnection = CreateObject("ADODB.Connection") 
    objConnection.Provider = "ADsDSOObject" 
    objConnection.Open "Active Directory Provider" 
    objCommand.ActiveConnection = objConnection 
     
    'Modify the following line to desired OU 
    Set objNewOU = GetObject("LDAP://OU=Disabled Computers,dc=test,dc=local") 
    Do Until oTS.AtEndOfStream 
            strComputer = oTS.ReadLine 
            strQuery = _ 
              "<LDAP://" & strDNSDomain & ">;(&(objectCategory=computer)(cn=" & strComputer & "));adspath,cn;subtree" 
            objCommand.CommandText = strQuery 
            Set RS = objCommand.Execute 
            While not RS.EOF 
                    strPath = RS.Fields("adspath") 
                    strName = "CN=" & RS.Fields("cn") 
                    oLS.Writeline(strPath) 
                    Set objMoveComputer = objNewOU.MoveHere(strPath,strName) 
                    RS.MoveNext 
            Wend 
    Loop

  3. #3
    Join Date
    Jan 2006
    Posts
    115

    Re: Script to move computers to another OU

    Thanks for the script, I used it and also modified it as per my needs. Thanks once again.

Similar Threads

  1. Replies: 6
    Last Post: 24-09-2010, 06:25 AM
  2. Program or Script to Move text around circle
    By Katty in forum Software Development
    Replies: 3
    Last Post: 19-11-2009, 09:23 AM
  3. Script to change ODBC settings on Vista Client Computers
    By SADIQ in forum Software Development
    Replies: 3
    Last Post: 03-06-2009, 07:25 PM
  4. Vista Computers Unable to see other computers on LAN
    By KaramChand in forum Networking & Security
    Replies: 0
    Last Post: 20-02-2009, 08:21 PM
  5. Batch script to move users to different OUs
    By Serrix in forum Active Directory
    Replies: 5
    Last Post: 23-12-2008, 06:45 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,929,182.54651 seconds with 17 queries