Flip display names (VBScript)

This code can be found in Chapter 5 of Exchange Server Cookbook

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the VBScript code from this site.

' This script was originally published in the Exchange Cookbook,
' (http://www.exchangebookcook.com). Written by Paul Robichaux, 
' Missy Koslosky, and Devin Ganger. Redistributed with permission 
' of the publisher, O'Reilly & Associates.

' This script flips the display name of existing objects to "lastname, firstname"
' ------ SCRIPT CONFIGURATION ------
 strDCName = "<serverName>"	' e.g. "Batman"
 strTargetContainer = "<OU or container>" ' e.g. "cn=users, dc=robichaux, dc=net"
'  ------ END CONFIGURATION ---------

Set theTargetOU = GetObject("LDAP://" & strTargetContainer)
theTargetOU.Filter = Array("user")
For each userItem in theTargetOU
	if instr(userItem.samAccountName, "$") = 0 then
		vLast = userItem.get("Sn")
		vFirst = userItem.get("GivenName")
 		vFullname = vLast + ", " + vFirst
		userItem.put "displayName", vFullName
 	   	userItem.setinfo
		WScript.echo userItem.samAccountName " is now " & userItem.displayName
	end if
Next

This code has been viewed 1478 times.

New from the creators of TechTasks.com: StatSheet.com