Microsoft KB Archive/300427

= How to Change Active Directory Display Names =

Article ID: 300427

Article Last Modified on 3/1/2007

-

APPLIES TO


 * Microsoft Windows 2000 Server
 * Microsoft Windows 2000 Advanced Server

-



This article was previously published under Q300427



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



MORE INFORMATION
After you migrate users from a Microsoft Windows NT 4.0 domain or another directory, you may have user's display names in the FirstName LastName format. If you want to change this to LastName, Firstname Middle format but the Active Directory users are not populated with First Name Last Names yet (as Q277717 requires), the following script takes the current display name, splits it into separate strings, rearranges them, and then writes them back to display names in the LastName, First Middle format. It also populates the LastName (SN), FirstName (givenName) and Middlename properties of the user.

This script does not populate the middle initials fields, instead, it appends anything after Fname Lastname to the end of the string. For example, Jane Doe is changed to Doe, Jane and John C. Doe is changed to Doe, John C., but the initials field is not populated.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

rem chgdisplay3.vbs - Changes the display names of all users in a given OU to the rem format of Lastname, Firstname Middle using the current displayName field and breaking this into seperate strings. 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 if instr(usr.displayName, &quot;,&quot;) = 0 then vTempName = usr.get(&quot;displayName&quot;) astrWords = split(vTempName) CountWords = UBound(astrWords) - LBound(astrWords) +1 if CountWords = 2 then vFirst = astrWords(0) vLast = astrWords(1) vFullname = vLast + &quot;, &quot; + vFirst usr.put &quot;Sn&quot;, vLast usr.put &quot;GivenName&quot;, vFirst end if           if CountWords = 3 then vFirst = astrWords(0) vMiddle = astrWords(1) vLast = astrWords(2) vFullname = vLast + &quot;, &quot; + vFirst + &quot; &quot; + vMiddle usr.put &quot;Sn&quot;, vLast usr.put &quot;GivenName&quot;, vFirst usr.put &quot;middleName&quot;, vMiddle end if

usr.put &quot;displayName&quot;, vFullName usr.setinfo wscript.echo vFullName end if   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

Keywords: kbhowto KB300427

-

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

© Microsoft Corporation. All rights reserved.