Automatically move computers into a certain OU (Server 2008)

What I'd like to achieve is this:
 
When a computer is joined to the domain and the computer name starts w/ "CR" that it be moved to the "Student Computers" OU.

I don't want to pre-stage. I'm running 2008 (R2) domain functional level is 2003.

Thanks!!
PapaSmurffAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
McKnifeConnect With a Mentor Commented:
Add a second line: pause

PS: Aargh. There was an additional "," that did not belong there... try
for /f %%a in ('dsquery computer "CN=Computers,DC=hcrhs,DC=k12,DC=nj,DC=us" -name CR*') do dsmove %%a -newparent ou="student computers",ou=workstations,DC=hcrhs,DC=k12,DC=nj,DC=us

Open in new window

0
 
Mike KlineCommented:
You can have all machines go to a certain OU using redircmp   http://technet.microsoft.com/en-us/library/cc770619(v=ws.10).aspx

There is no way to have them intelligently placed in an OU based on name.  You would have to script a computer join process to do something like that.

Thanks

Mike
0
 
McKnifeCommented:
...but of course you could setup a scheduled task at the DC that regularly moves any object based on name to your target OU using the dsmove command.
Although powershell rules, this is batch:

for /f %%a in ('dsquery computer "OU=SourceOU,DC=yourdomain,DC=localOrWhatever" -name CR*') do dsmove %%a -newparent ou=targetOU,DC=yourdomain,DC=localOrWhatever

Open in new window


This would solve it.
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 
PapaSmurffAuthor Commented:
Great. Thanks McKnife! Sorry for the delayed response just got back to work.
 
How would that look in task scheduler? Advanced task and browse to that as a .bat file??
Thanks.
0
 
McKnifeCommented:
Exactly. Execute as System, passw. left empty.
0
 
PapaSmurffAuthor Commented:
Ok, it didn't work but I'm horrible at scripting. This is what's in the bat file.

for /f %%a in ('dsquery computer "OU=Computers,DC=hcrhs,DC=k12,DC=nj,DC=us," -name CR*') do dsmove %%a -newparent ou=WorkStations, ou=Student Computers,DC=hcrhs,DC=k12,DC=nj,DC=us

Our domain is hcrhs.k12.nj.us. Joined computers go into the Computers OU and I'd like them to go to:
Workstations -> "Student Computers" OU

What did I mess up in the script?
Thanks again!
0
 
Mike KlineCommented:
Is that the Computers OU or the default computers containers your computers start in?

if it is the default container user

CN=Computers.....

instead of OU=Computers

Thanks

Mike
0
 
PapaSmurffAuthor Commented:
Yes, it is. I changed that to CN=
Didn't move the test computer. The rest of the script look ok?
Thanks,
Ron
0
 
McKnifeCommented:
I am about to setup a new vm testlab with 2012 R2 preview right now and won't be able to test and help you before in a few hours. But I will :)
0
 
McKnifeCommented:
Hi.

Should be
for /f %%a in ('dsquery computer "CN=Computers,DC=hcrhs,DC=k12,DC=nj,DC=us," -name CR*') do dsmove %%a -newparent ou="student computers",ou=workstations,DC=hcrhs,DC=k12,DC=nj,DC=us

Open in new window

0
 
PapaSmurffAuthor Commented:
Thanks McKnife. Still didn't work. How can I pause the .bat file to see if there are any error messages?
0
 
PapaSmurffAuthor Commented:
McKnife you da man!!! Thanks! Worked like a charm!
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.