Problem
This week I needed to remove a old domain in office 365 for a customer.
When trying to remove I received this message stating I needed to change some accounts and groups, because they still use the old domain.
In this case I needed to change 1 user and 6 groups, because they use the old domain as an alias.
Solution
This can only be done in powershell
I needed to change the PrimarySmtpAddress from 2 groups, and change the alias for 4 groups.
First check the current settings :
get-UnifiedGroup -Identity "GroupName" | select -ExpandProperty emailaddresses
SMTP:GroupName@OldDomain.com
smtp:GroupName@NewDomain.com
You can change the PrimarySmtpAddress of a group with :
Set-Group "GroupName" -WindowsEmailAddress "GroupName@NewDomain.com"
Check again :
get-UnifiedGroup -Identity "GroupName" | select -ExpandProperty emailaddresses
smtp:GroupName@OldDomain.com
SMTP:GroupName@NewDomain.com
You can remove the alias of a group by :
set-unifiedGroup -Identity "GroupName" -EmailAddress @{remove='GroupName@OldDomain.com'}
Error
In this case I received an Error :
There should be atleast one MOERA in Email Addresses.
+ CategoryInfo : NotSpecified: (:) [Set-UnifiedGroup], RecipientTaskException
+ FullyQualifiedErrorId : [Server=VI1PR1001MB1007,RequestId=5f4a4103-72c8-4971-a0b5-3c111adc04c4,TimeStamp=29/10/2019 14:29:25] [FailureCategory=Cmdlet-RecipientTaskException] 237F131F,Microsoft.Exchange.Management.RecipientTasks.SetUnifiedGroup
+ PSComputerName : outlook.office365.com
What is a MOERA ?
MOERA: Microsoft Online Email Routing Address
Why is it giving this error ?
The error is thrown because the group does not have a default domain email address.
The default domain address of a tenant is XXX.onmicrosoft.com
So after the error, we know what to do :
set-unifiedGroup -Identity "GroupName" -EmailAddress @{add='email@TenantName.Onmicrosoft.com'}
Get-unifiedGroup -Identity "GroupName" | FL
smtp:GroupName@OldDomain.com
SMTP:GroupName@NewDomain.com
smtp: email@TenantName.Onmicrosoft.com
We now can remove the OldDomain :
set-unifiedGroup -Identity "GroupName" -EmailAddress @{remove='GroupName@OldDomain.com'}
Get-unifiedGroup -Identity "GroupName" | FL
SMTP:GroupName@NewDomain.com
smtp: email@TenantName.Onmicrosoft.com
The OldDomein emailaddress is now removed !