Sort the Computers in the ADS according to the file

Hi,

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.

Regards
Sharath
LVL 11
bsharathAsked:
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
setlocal
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%"
)
0
 
MikkkCommented:
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?
0
 
bsharathAuthor Commented:
Yes you are correct..
0
 
MikkkConnect With a Mentor Commented:
Here is a very good article showing the way to find and move objects from and to OUs:
http://www.microsoft.com/technet/scriptcenter/resources/qanda/jan05/hey0121.mspx

You only need to build a bucle in vbs that iterates in the file, search the machine and moves it to the new OU.
0
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.