Active Directory Cookbook, 3rd Edition
5.6.1 Problem
You want to move some or all of the objects in an OU to a different OU. You may need to do this as part of a domain restructuring effort. 5.6.2 Solution
5.6.2.1 Using a graphical user interface
5.6.2.2 Using a command-line interface
> for /F "usebackq delims=""" %i in (`dsquery * "<OldOrgUnitDN>" -scope onelevel`)[RETURN] do dsmove -newparent "<NewOrgUnitDN>" %i 5.6.2.3 Using VBScript
' This code moves objects from the "old" OU to the "new" OU ' ------ SCRIPT CONFIGURATION ------ strOldOrgUnit = "<OldOrgUnitDN>" ' e.g. ou=Eng Tools,dc=rallencorp,dc=com strNewOrgUnit = "<NewOrgUnitDN>" ' e.g. ou=Tools,dc=rallencorp,dc=com ' ------ END CONFIGURATION --------- set objOldOU = GetObject("LDAP://" & strOldOrgUnit) set objNewOU = GetObject("LDAP://" & strNewOrgUnit) for each objChildObject in objOldOU Wscript.Echo "Moving " & objChildObject.Name objNewOU.MoveHere objChildObject.ADsPath, objChildObject.Name next 5.6.3 Discussion
5.6.3.1 Using a graphical user interface
If you want to move more than 2,000 objects at one time, you will need to modify the default number of objects displayed as described in Discussion section of Recipe 5.3. 5.6.3.2 Using a command-line interface
Since dsmove can move only one object at a time, I had to use the for command to iterate over each child object returned from dsquery. Also note that if you want to move more than 100 objects, you'll need to specify the -limit xx option with dsquery, where xx is the maximum number of objects to move (use 0 for all). 5.6.3.3 Using VBScript
For more information on the MoveHere method, see Recipe 4.17. 5.6.4 See Also
Recipe 4.17 for moving objects, Recipe 5.3 for enumerating objects in an OU, and MSDN: IADsContainer::MoveHere |