During a recent Office 365 migration project I ran into an issue on the on-premises Exchange 2013 platform, when trying to create Mail User objects for the migrated mailboxes.
The following error appeared when adding a new Mail User:
ExchangeGuid is mandatory on UserMailbox.
Database is mandatory on UserMailbox.
After first verifying that the Exchange server was able to route mail to the Exchange Online, I started looking at the user accounts in Active Directory, using the Attribute Editor in Active Directory Users and Computers.
Going through the users attributes, I noticed that the Exchange attribute msExchHomeServerName was still populated with a LegacyExchangeDN value, despite the users did not any longer have mailboxes in the on-premises Exchange organization.
The root cause behind this could be that an internal mailbox decommissioning process failed, so the msExchHomeServerName attribute was not cleared properly on the user objects, as it should have been.
Before proceeing with the change, I first exported the UserPrincipalName and msExchHomeServerName values to a CSV file – just as a precaution.
To first view the output:
Get-ADUser –filter * -Properties msExchHomeServerName | Where-Object {$_.msExchHomeServerName –ne $null} | Sort-Object -Property UserPrincipalName | Select-object Userprincipalname, msExchHomeServerName
And to export the output to a CSV file:
Get-ADUser –filter * -Properties msExchHomeServerName | Where-Object {$_.msExchHomeServerName –ne $null} | Sort-Object -Property UserPrincipalName | Select-object Userprincipalname, msExchHomeServerName | Export-CSV C:\Temp\ExchHomeServer.csv –NoTypeInformation
After clearing the msExchHomeServerName attribute, I could create the Mail User objects using the Exchange Admin Center og using the Exchange Management Shell.
Shortly after, the mail flow started to route messages correctly to the users new Exchange Online mailboxes.