Get rid of trailing whitespace in DisplayName attribute…

Posted by in Exchange, PowerShell

Exchange 2007/2010 doesn’t like trailing whitespaces in the DisplayName of users. If a whitespace exists you will have issues when trying to manage the mailbox via EMC or EMS. This can be very annoying when you have automated systems that create users and append an annoying space to the end of the DisplayName.

Here’s a command to find them and trim the whitespace off of the end of the DisplayName attribute:

Get-Mailbox -Filter {DisplayName -like "* "} -ResultSize:Unlimited |
   ForEach {Set-Mailbox -Identity $_ -DisplayName $_.DisplayName.TrimEnd()}