6.6. Renaming a User

Problem

You want to rename a user.

Solution

Using a graphical user interface

  1. Open the Active Directory Users and Computers snap-in.

  2. In the left pane, right-click on the domain and select Find.

  3. Type the name of the user and click Find Now.

  4. In the Search Results, right-click on the user and select Rename.

  5. You can modify the Full Name, Last Name, First Name, Display Name, User Principal Name (logon name), and SAM Account Name (pre-Windows 2000).

  6. Click OK after you are done.

Using a command-line interface

The following command will rename the RDN of the user:

> dsmove "<UserDN>" -newname "<NewUserName>"

You can modify the UPN (-upn), First Name (-fn), Last Name (-ln), and Display Name (-display) using the dsmod user command. For example, the following command would change the user’s UPN and last name:

> dsmod user "<UserDN>" -upn "<NewUserUPN>" -ln "<NewUserLastName>"

Using VBScript

' This code renames the RDN of a user and the sAMAccountName attribute.
' ------ SCRIPT CONFIGURATION ------
strParentDN    = "<ParentDN>"    ' e.g. cn=Users,dc=rallencorp,dc=com
strUserOldName = "<OldUserName>" ' e.g. jsmith
strUserNewName = "<NewUserName>" ' e.g. jim ' ------ END CONFIGURATION --------- set objCont = GetObject("LDAP://" & strParentDN) objCont.MoveHere "LDAP://cn=" & strUserOldName & "," & strParentDN, _ "cn=" & strUserNewName set objUser = GetObject("LDAP://cn=" & strUserNewName & "," & strParentDN) objUser.Put "sAMAccountName", strUserNewName objUser.SetInfo WScript.Echo "Rename successful" ...

Get Active Directory Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.