Removing leading/trailing white spaces from displayName using PowerShell
I am moving thousands of Exchange 2003 mailboxes to Exchange Server 2007 over this weekend. Most of these are student mailboxes which have been provisioned using another third party system. Due to a minor bug, the third party system added a trailing space to every student’s display name.
A trailing space is a whitespace at the end of the displayName string. This may look like a very small issue, but unfortunately Exchange Server 2007 is very fussy about such things:
The DisplayName property contains leading or trailing whitespace, which must be removed.
Exchange 2007 would not let me move these mailboxes across from Exchange 2003 unless I correct the DisplayName property for all the mailboxes.
I have several thousands of mailboxes having an ‘inconsistent’ display name. Correcting each of these manually would have been a frustrating exercise – so I decided to coin my own PowerShell command to remove leading/trailing spaces from all mailboxes in a given mailbox database. ![]()
get-mailbox -Database ‘SERVER\MailStore’ -ResultSize 4850 | Foreach { Set-Mailbox -Identity $_.Identity -DisplayName $_.DisplayName.Trim() }
where SERVER is the Exchange 2003 server hosting the mailboxes you want to modify, MailStore is the Mailbox store on that server containing those mailboxes. I set the ResultSize to 4850 because I have more than 4000 mailboxes and by default the get-mailbox command fetches only 1000.
Leave an opinion!