Thursday, August 02, 2007

Exchange 2007, legacyExchangeDN and mail-enabled user conversions

This was an interesting topic that just recently came up in the TechNet forums. The original poster came up with a good solution.

Essentially, during his migration, he is converting mail-enabled users to mailbox-enabled users, but their legacyExchangeDN attribute is changing. This causes problems when users reply to messages that person originally sent or if they have his/her name in their Outlook nickname (NK2) file. Essentially, the legacyExchangeDN no longer exists in the directory so existing messages and NK2 entries don't work anymore.

The solution is to document the account's legacyExchangeDN before removing the mail attributes from the mail-enabled user and then adding that legacyExchangeDN address to the new mailbox-enabled user as an X500 address. The person that was looking for a solution (Jim Mulvey) wrote a nice PowerShell / EMS script to handle this.

$SourceRecipient = Get-Recipient $emailaddress
If ($SourceRecipient.RecipientType -eq "MailUser" {
$OldLegacyExchangeDN = [string]$SourceRecipient.LegacyExchangeDN
$DistinguishedName = [string]$SourceRecipient.Identity.ToCanonicalName()
$EmailAddresses = $SourceRecipient.EmailAddresses
Disable-MailUser $DistinguishedName -confirm:$false


#An inexplicable 5 minute delay here would ensure the Mailbox object gets the
#same LegacyExchangeDN as the old MailUser object. But we really shouldn't have
#the user's email bounce for 5 minutes before we welcome them to Exchange.

$TargetRecipient = Enable-Mailbox -identity $DistinguishedName -database 'Server01/SG01/DB01'
Set-Mailbox $TargetRecipient -EmailAddresses $EmailAddresses

#Check to see if the New LegacyExchangeDN is the same as the old one
#If not, add the old LegacyExchangeDN as an additional Proxy Address

If ([string]$TargetRecipient.LegacyExchangeDN -ne $OldLegacyExchangeDN) {
$EmailAddresses += [Microsoft.Exchange.Data.CustomProxyAddress]("X500:" + $OldLegacyExchangeDN)
Set-Mailbox $TargetRecipient -EmailAddresses $EmailAddresses
}

"Conversion of user from MailUser to Mailbox complete."
} Else { throw "This script only converts MailUser objects to Mailbox objects" }

Labels: