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).

link|improve this question
feedback

2 Answers

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.

link|improve this answer
+1 for doing it in 1 command – Nixphoe Jun 1 '11 at 16:05
feedback

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) to 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) dsmove %%b -newparent OU=newOU,DC=domain,DC=local

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

link|improve this answer
1  
You shouldn't need the FQDN for dsmove afaik. – MDMarra Jun 1 '11 at 13:19
Sweet, never actually needed to move things in bulk before. But I've read much about the command. Good to know! Glad I got close to the same answer you did :) – Nixphoe Jun 1 '11 at 13:22
I had to dig into my old batch scripts :) I've moved a lot of this type of thing to PowerShell now. – MDMarra Jun 1 '11 at 13:23
1  
@Grey Tux You should run the script in cmd not powershell. – jscott Jun 1 '11 at 13:36
1  
it must be %a instead of %%a – Grey Tux Jun 1 '11 at 14:10
show 7 more comments
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.