Article ID: 277717 - View products that this article applies to.
This article was previously published under Q277717
This article describes how to change the display names of Active Directory users with Active Directory Services Interface (ADSI) script.
By default, when a new user is created, the Display Name box is generated in "FirstName LastName" format. You can change existing users to a "LastName, FirstName" format if you use ADSI Visual Basic (VB) scripting.
The default format of newly created users can be changed to reflect the LastName, FirstName format if you use the ADSI Edit utility, and then you alter the createDialog property in the DisplaySpecifiers node. For more information about how to change the default format, click the following article number to view the article in the Microsoft Knowledge Base:
(http://support.microsoft.com/kb/250455/ )How to change display names of Active Directory users
300427The following script can change existing users in a given organizational unit (OU) to the Lastname, Firstname format.
(http://support.microsoft.com/kb/300427/ )How to change Active Directory display names
Any users that are created after you make the change discussed in the preceding article (Q250455), can also have a different format for the Distinguished Name. For example, a user created with the default naming rule could have the following Distinguished Name:
rem chgdisplay.vbs - Changes the display names of all users in a given OU to the rem format of Lastname, Firstname. rem Usage = cscript chgdisplay.vbs "OU=My Ou, DC=My Domain, DC=com" rem OU must be enclosed in quotes if it contains spaces in the name Dim strTargetOU ParseCommandLine() wscript.echo strTargetOU wscript.echo wscript.echo "Changing Display names of users in " & strTargetOU Set oTargetOU = GetObject("LDAP://" & strTargetOU) oTargetOU.Filter = Array("user") For each usr in oTargetOU if instr(usr.SamAccountName, "$") = 0 then vLast = usr.get("Sn") vFirst = usr.get("GivenName") vFullname = vLast + "\, " + vFirst usr.put "displayName", vFullName usr.setinfo wscript.echo usr.displayName end if Next Sub ParseCommandLine() Dim vArgs set vArgs = WScript.Arguments if vArgs.Count <> 1 then DisplayUsage() Else strTargetOU = vArgs(0) End if End Sub Sub DisplayUsage() WScript.Echo WScript.Echo "Usage: cscript.exe " & WScript.ScriptName & " <Target OU to change users display names in>" WScript.Echo "Example: cscript " & WScript.ScriptName & " " & chr(34) & "OU=MyOU,DC=MyDomain,DC=com" & chr(34) WScript.Quit(0) End Sub
Dn: CN=Joe Smith,OU=Sales,DC=acme,DC=com
A user created after this change to the default naming rule has the following Distinguished Name that contains an escape character before the comma:
Dn: CN=Smith\, John,OU=Sales,DC=acme,DC=com
The preceding suggestions should be considered if you use ADSI scripting to change the users. For example:
Note If you do not provide a surname or a given name, you may receive an error message.
Set usr = GetObject("LDAP://CN=Smith\, John,OU=Sales,DC=acme,DC=com") usr.Put "pwdLastSet", CLng(0) usr.SetInfo