Microsoft KB Archive/277717

= How to change the display names of Active Directory users with Active Directory Services Interface script =

Article ID: 277717

Article Last Modified on 10/31/2006

-

APPLIES TO


 * Microsoft Windows 2000 Server
 * Microsoft Windows 2000 Advanced Server

-



This article was previously published under Q277717



SUMMARY
This article describes how to change the display names of Active Directory users with Active Directory Services Interface (ADSI) script.



MORE INFORMATION
By default, when a new user is created, the Display Name box is generated in &quot;FirstName LastName&quot; format. You can change existing users to a &quot;LastName, FirstName&quot; 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:

250455 How to change display names of Active Directory users

300427 How to change Active Directory display names

The following script can change existing users in a given organizational unit (OU) to the Lastname, Firstname format. 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 &quot;OU=My Ou, DC=My Domain, DC=com&quot; rem OU must be enclosed in quotes if it contains spaces in the name

Dim strTargetOU

ParseCommandLine

wscript.echo strTargetOU wscript.echo wscript.echo &quot;Changing Display names of users in &quot; & strTargetOU

Set oTargetOU = GetObject(&quot;LDAP://&quot; & strTargetOU)

oTargetOU.Filter = Array(&quot;user&quot;)

For each usr in oTargetOU

if instr(usr.SamAccountName, &quot;$&quot;) = 0 then vLast = usr.get(&quot;Sn&quot;) vFirst = usr.get(&quot;GivenName&quot;) vFullname = vLast + &quot;\, &quot; + vFirst usr.put &quot;displayName&quot;, 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 &quot;Usage: cscript.exe &quot; & WScript.ScriptName & &quot; &quot; WScript.Echo &quot;Example: cscript &quot; & WScript.ScriptName & &quot; &quot; & chr(34) & &quot;OU=MyOU,DC=MyDomain,DC=com&quot; & chr(34) WScript.Quit(0) End Sub 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:

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: Set usr = GetObject(&quot;LDAP://CN=Smith\, John,OU=Sales,DC=acme,DC=com&quot;) usr.Put &quot;pwdLastSet&quot;, CLng(0) usr.SetInfo Note If you do not provide a surname or a given name, you may receive an error message.

Keywords: kbenv kbhowto kbnetwork KB277717

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.