Sort the Computers in the ADS according to the file

Posted on 2007-10-16
Last Modified: 2011-09-20

I have a txt file which has the machine names so need a way that a sript in which i have mentioned the OU path.The script has to find all computers in the file and move them to the specified OU.

Question by:bsharath
    LVL 8

    Expert Comment

    If I've understand you: You want to move computers form "active directory users and computers" to a new OU according to a computer list on a txt file?
    isn't it?
    LVL 11

    Author Comment

    Yes you are correct..
    LVL 8

    Assisted Solution

    Here is a very good article showing the way to find and move objects from and to OUs:

    You only need to build a bucle in vbs that iterates in the file, search the machine and moves it to the new OU.
    LVL 82

    Accepted Solution

    That should do the trick. Just adjust the "NewOU" and "InputFile" variables according to your needs.
    As usual, try with a list of test machines first.

    @echo off
    set NewOU=ou=SomeComputers,ou=SomeOU,dc=your,dc=domain,dc=local
    set InputFile=C:\Temp\ComputerMove.txt
    for /f "tokens=1" %%a in ('type "%InputFile%"') do (
      dsquery computer -name "%%a" | dsmove -newparent "%NewOU%"

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Want to promote your upcoming event?

    Is your company attending an event or exhibiting at a trade show soon? Are you speaking at a conference? Spread the word by using a promotional banner in your email signature. This will ensure your organization’s most important contacts are in the know.

    Some time ago I faced the need to use a uniform folder structure that spanned across numerous sites of an enterprise to be used as a common repository for the Software packages of the Configuration Manager 2007 infrastructure. Because the procedu…
    Welcome to my series of short tips on migrations. Whilst based on Microsoft migrations the same principles can be applied to any type of migration. My first tip Migration Tip #1 – Source Server Health can be found here: http://www.experts-exchang…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now