Move computer accounts to new OU in bulk

I have an OU with around 2500 computers. I need to move 580 of them to another OU. Is there a way to do this with a batch file? I have a text file with the computernames (not the FQDN).


FOR /f %%i in (C:\path\to\textfile.txt) do (

  dsquery computer -name %%i | dsmove -newparent OU=newOU,DC=domain,DC=com

)

That should take care of it for you.

edit: It's been a while since I've had to use dsmove :) It needs the DN of the object that you're moving, so I added the dsquery in front of a pipe to get the DN from the list and then pipe it to dsmove. This should work fine now for a list of just NetBIOS names.


A small error in Nixphoe's answer -- to vs do and a missing do

FOR /f %%a in (file.txt) do dsquery computer -name %%a >> fqdnfile.txt

FOR /f %%b in (fqdnfile.txt) do dsmove %%b -newparent OU=newOU,DC=domain,DC=local

Assuming that you have the names of your comptuers in a text file and 1 on each line youc an run the following command to export the fqdn of them

FOR /f %%a in (file.txt) DO dsquery computer -name %%a >> fqdnfile.txt

Then run the following command to move them. Please use the echo command in lue of dsmove to test this first

FOR /f %%b in (fqdnfile.txt) DO dsmove %%b -newparent OU=newOU,DC=domain,DC=local

Test it out. Let me know if it doesn't work.