6.6. Renaming a User
Problem
You want to rename a user.
Solution
Using a graphical user interface
Open the Active Directory Users and Computers snap-in.
In the left pane, right-click on the domain and select Find.
Type the name of the user and click Find Now.
In the Search Results, right-click on the user and select Rename.
You can modify the Full Name, Last Name, First Name, Display Name, User Principal Name (logon name), and SAM Account Name (pre-Windows 2000).
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" ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access