Sort the Computers in the ADS according to the file


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.

LVL 11
Who is Participating?
oBdAConnect With a Mentor Commented:
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%"
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?
bsharathAuthor Commented:
Yes you are correct..
MikkkConnect With a Mentor Commented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.