Recipe15.11.Moving an Object


Recipe 15.11. Moving an Object

Problem

You want to move an object to a different container or OU in the same domain.

Solution

Using a graphical user interface

  1. Open ADSI Edit.

  2. If an entry for the naming context you want to browse is not already displayed, do the following:

  3. Right-click on ADSI Edit in the right pane and click Connect to....

  4. Fill in the information for the naming context, container, or OU where the object is currently. Click on the Advanced button if you need to enter alternate credentials.

  5. In the left pane, browse to the container or OU that contains the object you want to modify. Once you've found the object, right-click on it and select Move.

  6. Browse to the new parent of the object, select it and click OK.

Using a command-line interface
> dsmove "<ObjectDN>" -newparent  "<NewParentDN>"

Using VBScript
' This code moves an object from one location to another in the same domain. ' ------ SCRIPT CONFIGURATION ------ strNewParentDN = "LDAP://<NewParentDN>" strObjectDN    = "LDAP://cn=jsmith,<OldParentDN>" strObjectRDN   = "cn=jsmith" ' ------ END CONFIGURATION ---------     set objCont = GetObject(strNewParentDN) objCont.MoveHere strObjectDN, strObjectRDN

Discussion

Using a graphical user interface

If the parent container of the object you want to move has a lot of objects in it, you may want to add a new connection entry for the DN of the object you want to move. This may save you time searching through the list of objects in the container. You can do this by right-clicking ADSI Edit and selecting Connect to.... Under Connection Point, select Distinguished Name and enter the DN of the object you want to move.

Using a command-line interface

The dsmove utility can work against any type of object (there are no limitations as with dsadd and dsmod). The first parameter is the DN of the object to be moved. The second parameter is the new parent container of the object. The -s parameter can additionally be used to name a specific server to work against.

Using VBScript

The MoveHere method can be tricky, so an explanation of how to use it to move objects is in order. First, you need to call GetObject on the new parent container. Then call MoveHere on the parent container object with the ADsPath of the object to move as the first parameter and the RDN of the object to move as the second.

The reason for the apparent duplication of cn=jsmith in the MoveHere method is that the same method can also be used for renaming objects within the same container.

See Also

MS KB 313066 (HOW TO: Move Users, Groups, and Organizational Units Within a Domain in Windows 2000) and MSDN: IADsContainer::MoveHere



Windows Server Cookbook
Windows Server Cookbook for Windows Server 2003 and Windows 2000
ISBN: 0596006330
EAN: 2147483647
Year: 2006
Pages: 380
Authors: Robbie Allen

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net