Wednesday, February 6, 2019

How to Update Office 365 Groups Primary Email Address

The other day I got asked if it was possible to update the primary SMTP address of multiple Office 365 Groups in one go. It turns out that, for this particular tenant, the default domain was still the one, meaning all the groups created until then had an email address of instead of

To do this, we have to use PowerShell as it is not possible to change the email address of such group using the EAC.

First, we connect to Exchange Online PowerShell, and then we need to use the *-UnifiedGroup cmdlet.

To retrieve the list of groups that need to be updated, we use the following code:
Get-UnifiedGroup -ResultSize Unlimited | Where {$_.PrimarySmtpAddress -like "*"}

To update the primary SMTP address of an Office 365 Group, we use the Set-UnifiedGroup cmdlet with the PrimarySmtpAddress parameter:
Set-UnifiedGroup “Test Group” -PrimarySmtpAddress “”

Below you can see that the existing primary email address becomes an alias of the group, so no alias/email addresses are lost:

To do this is a large scale, we can use a script like the following:
Get-UnifiedGroup -ResultSize Unlimited | ? {$_.PrimarySmtpAddress -like "*"} | % {
  $smtp = $_.PrimarySmtpAddress
  $newSmtp = $smtp.Split("@")[0] + ""
  # If all the groups’ email addresses are in the alias@ format, then we can simply use the following instead
  # $newSmtp = "$($_.Alias)"

  Write-Host "Updating ""$($_.DisplayName)"" from $smtp to $newSmtp"
  Set-UnifiedGroup $_.Identity -PrimarySmtpAddress $newSmtp

No comments:

Post a Comment