Wednesday, May 7, 2008

Modifying AD/Exchange Display names


Our organization has been going through a lot of change and to facilitate this, we have had to change a number of users display names. Our display names are LASTNAME, FIRSTNAME DEPTIDCODE. Mine is Wall, Murray ITO Ito being the Information Technology Office. Our display code can change quite often based on various inputs and political factors. Here is the code that I have been using to change the display names:

## Read from a group the users you want to change You have to have the Quest tools and the SNAP IN loaded.
## Read all the users from a group

$g=get-qadgroup -display "tempgroup4"


## Loop Through
for ($members=0; $members -le $g.member.count-1 ;$members++)
{
$b=$g.member[$members] $c=[ADSI]"LDAP://$b"
$Display=[STRING]$c.Displayname
#$display
#$first=[STRING]$c.givenname
#$last=[STRING]$c.sn
$newdisplay=$display.substring(0,$display.length-3)
$newdisplay=$newdisplay+"NewCODE"
$newdisplay $c.extensionattribute5="Old Display Name " + $display
$c.Displayname=$newdisplay
$c.setinfo()
}
#

At first I thought I would regenerate the entire display name but as I go through, I see that modifications, minor ones, but mods none the less have been made to. These changes include editing out special characters, names, ETC. So I copy the Old ($display.length-3) 3 being the length of characters in the old code. and just add in the new text. I then write the old one to an AD attribute extensionattribute5 for reference. I can write a quick little script to get it back or to aid the help desk in troubleshooting...