Active Directory Scripts to move Computers

  • Thread starter Thread starter stefanoc
  • Start date Start date
S

stefanoc

I am trying to find a script that will move computers from the default
computers container, into an OU based on their location fields.

Example:

Location = Human Resources - Move to OU Human Resources

Has anyone got a script that can do this, or that can point me in the
right direction.
 
It's likely going to require VB. Search google groups for: script move OU,
you'll find plenty there.

Ed
 
I am trying to find a script that will move computers from the default
computers container, into an OU based on their location fields.

Example:

Location = Human Resources - Move to OU Human Resources

Has anyone got a script that can do this, or that can point me in the
right direction.


See tips 7382 and 7992 and links in the 'Tips & Tricks' at http://www.jsiinc.com

@echo off
setlocal ENABLEDELAYEDEXPANSION
set qry=dsquery * domainroot -filter "(&(objectCategory=Computer)(objectClass=Computer))" -attr distinguishedName location -L -LIMIT 0
for /f "Tokens=1*" %%a in ('%qry%') do (
if /i "%%a" EQU "distinguishedName:" set DN=%%b
if /i "%%a" EQU "location:" if /i "%%b" EQU "Human Resources" DSMOVE !DN! -newparent xxxxxxxxx
)
endlocal



Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com
 
Ed Siff said:
It's likely going to require VB. Search google groups for: script move OU,
you'll find plenty there.

Not to pick nits, but I doubt that one would require VB - VBScript by itself
would probably suffice.

Of course, the specific application might have some unforeseen ambiguities.
OU names (i.e. RDN or canonical name) need not be unique across AD. The
script might need to make some choices between the "Human Resources" OU
found in the "Management" OU, and the "Administrative" OU, for example.

The question I would ask the OP is: how did the computer accounts come to
have their location attributes set? If this was input by a user or operator,
is there a chance of a spelling error, and how would this be handled by your
script?

If the location attribute setting is at least partly automated, then perhaps
that process could be amended to also adjust the OU. One possibility could
be to present to the person setting up the workstation a drop-down list of
all possible OU's and have them pick the correct one.


/Al
 
Back
Top