Recipe15.13.Renaming an Object


Recipe 15.13. Renaming an Object

Problem

You want to rename an object and keep it in its current container or OU.

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:

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

    2. Fill in the information for the naming context, container, or OU that contains the object you want to rename. Click on the Advanced button if you need to enter alternate credentials.

  3. In the left pane, browse to container or OU where the object you want to modify is. Once you've found the object, right-click on it and select Rename.

  4. Enter the new name and click OK.

Using a command-line interface
> dsmove "<ObjectDN>" -newname "<NewName>"

Using VBScript
' This code renames an object and leaves it in the same location. ' ------ SCRIPT CONFIGURATION ------ strCurrentParentDN = "<CurrentParentDN>" strObjectOldName   = "cn=<OldName>" strObjectNewName   = "cn=<NewName>" ' ------ END CONFIGURATION ---------     set objCont = GetObject("LDAP://" & strCurrentParentDN) objCont.MoveHere "LDAP://" & strObjectOldName & "," & _                  strCurrentParentDN, strObjectNewName

Discussion

Before you rename an object, ensure no applications reference it by name. You can make objects rename-safe by requiring all applications storing a reference to objects use the GUID of the object, not the name. The GUID (stored in the objectGUID attribute) is guaranteed to be unique and does not change when an object is renamed.

It is worth pointing out that by rename, I strictly mean renaming the object itself in the directory. If a user had a name change and thus need to be renamed, you may need to modify multiple attributes, such as sn (surname), sAMAccountName, userPrincipalName, etc.

Using a graphical user interface

If the parent container of the object you want to rename has a lot of objects in it, you may want to add a new connection for the DN of the object you want to rename. 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 rename.

Using a command-line interface

The two parameters that are needed to rename an object are the original DN of the object and the new RDN (-newname). The -s option can also be used to specify a server name to work against.

Using VBScript

The MoveHere method can be tricky to use, so an explanation of how to use it to rename objects is in order. First, you need to call GetObject on the parent container of the object you want to rename. Then call MoveHere on the parent container object and specify the ADsPath of the object to rename as the first parameter. The new RDN including prefix (e.g., cn=) of the object should be the second parameter.

See Also

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