skip to Main Content

Remove alias from Microsoft 365 Group

Remove alias from Microsoft 365 Groups in your cloud-based organization. The Microsoft 365 group is also known as Unified Group. A Unified Group is only available in the cloud. To remove an alias from Unified Group, you can use Microsoft 365 admin center or PowerShell. But, if you want to bulk remove alias from Unified Groups, PowerShell will save you time. In this article, we will remove alias address from Unified Group and bulk remove alias address from Unified Groups with PowerShell.

Introduction

Remember that you need to connect to Exchange Online PowerShell V2 before running the cmdlets and Remove-Alias-M365-Group.ps1 PowerShell script.

PS C:\> Connect-ExchangeOnline

Remove alias from Microsoft 365 Group

Get Microsoft 365 group

Run Get-UnifiedGroup cmdlet and list Microsoft 365 Groups.

PS C:\> Get-UnifiedGroup -ResultSize Unlimited | Select-Object DisplayName,PrimarySmtpAddress | Sort-Object DisplayName

DisplayName PrimarySmtpAddress
----------- ------------------
Group1      group1@exoip.com  
Group2      group2@exoip.com  

Get Microsoft 365 group email addresses

Expand the email addresses for the Microsoft 365 Group. In our example, the group1@exoip.com group.

PS C:\> Get-UnifiedGroup -Identity group1@exoip.com | Select-Object -ExpandProperty EmailAddresses | Sort-Object
SMTP:group1@exoip.com
smtp:group1@M365x877334.onmicrosoft.com
smtp:group1alias@exoip.com
smtp:group1new@exoip.com
SPO:SPO_b48f9d1b-80ee-4bee-b5a1-0c07cdb24f82@SPO_d032a20d-16c9-4e5b-87c3-30b055ded8cc

Remove Microsoft 365 Group alias

Remove alias with the Set-UnifiedGroup cmdlet and EmailAddresses parameter. In this example, we will remove the smtp:group1alias@exoip.com address.

PS C:\> Set-UnifiedGroup -Identity group1@exoip.com -EmailAddresses @{Remove="group1alias@exoip.com"}

Verify Microsoft 365 Group alias removal

Verify that alias address is successfully removed.

PS C:\> Get-UnifiedGroup -Identity group1@exoip.com | Select-Object -ExpandProperty EmailAddresses | Sort-Object
SMTP:group1@exoip.com
smtp:group1@M365x877334.onmicrosoft.com
smtp:group1new@exoip.com
SPO:SPO_b48f9d1b-80ee-4bee-b5a1-0c07cdb24f82@SPO_d032a20d-16c9-4e5b-87c3-30b055ded8cc

Everything looks great!

What if you want to remove aliases from all Microsoft 365 Groups? Or a specific domain from all Microsoft 365 groups? Let’s have a look at that in the next step.

Bulk remove alias from Microsoft 365 Group

Prepare remove alias from Microsoft 365 Group PowerShell script

Download Remove-Alias-M365-Group.ps1 script or copy and paste the below code in Notepad. Give it the name Remove-Alias-M365-Group.ps1 and place it in the C:\scripts folder. Create a script folder if you don’t have one.

# Get all Microsoft 365 groups
$Groups = Get-UnifiedGroup -ResultSize Unlimited

# Loop through each group
foreach ($Group in $Groups) {

    # Change @contoso.com to the domain that you want to remove
    $Group.EmailAddresses  | Where-Object { ($_ -clike "smtp*") -and ($_ -like "*@contoso.com") } |

    # Perform operation on each item
    ForEach-Object {

        # Remove the -WhatIf parameter after you tested and are sure to remove the alias
        Set-UnifiedGroup $Group.Name -EmailAddresses @{remove = $_ } -WhatIf

        # Write output
        Write-Host "Removing $_ from $Group" -ForegroundColor Green
    }
}

Change the @contoso.com value to the domain that you want to remove from the mailboxes.

A couple of examples:

  • Example 1: Remove alias addresses with the name tajran. Add “*tajran*“.
  • Example 2: Remove alias addresses with the domain exoip.com. Add “*@exoip.com“.

In my example, this is how it looks.

# Get all Microsoft 365 groups
$Groups = Get-UnifiedGroup -ResultSize Unlimited

# Loop through each group
foreach ($Group in $Groups) {

    # Change @contoso.com to the domain that you want to remove
    $Group.EmailAddresses  | Where-Object { ($_ -clike "smtp*") -and ($_ -like "*@exoip.com") } |

    # Perform operation on each item
    ForEach-Object {

        # Remove the -WhatIf parameter after you tested and are sure to remove the alias
        Set-UnifiedGroup $Group.Name -EmailAddresses @{remove = $_ } -WhatIf

        # Write output
        Write-Host "Removing $_ from $Group" -ForegroundColor Green
    }
}

In the next step, you are going to run the script and see it in action.

Run remove alias from Microsoft 365 Group PowerShell script

Change directory to the script path and run the Remove-Alias-M365-Group.ps1 script. The script will go through all the Unified Groups in the environment.

Good to know is that the -WhatIf parameter is added in the script. If you run the script, nothing will happen in the environment. You will get an output showing what will happen.

In our example, the script will bulk remove all the alias addresses with the domain @exoip.com. After running the script, confirm that these are the alias addresses that need to be removed.

PS C:\> cd C:\scripts
PS C:\scripts> .\Remove-Alias-M365-Group.ps1
What if: Setting unified group Identity:"group2_a6e165bf-936b-4736-9793-26b146f6dab2".
Removing smtp:group2alias2@exoip.com from Group2
What if: Setting unified group Identity:"group2_a6e165bf-936b-4736-9793-26b146f6dab2".
Removing smtp:group2alias1@exoip.com from Group2
What if: Setting unified group Identity:"group2_a6e165bf-936b-4736-9793-26b146f6dab2".
Removing smtp:group2alias@exoip.com from Group2
What if: Setting unified group Identity:"group1_db4bfda1-d553-4916-885b-2d439543d723".
Removing smtp:group1new@exoip.com from Group1

Remove the -WhatIf parameter from the PowerShell script and rerun the script. The alias addresses are removed in bulk from Microsoft 365 Groups.

PS C:\scripts> .\Remove-Alias-M365-Group.ps1
Removing smtp:group2alias2@exoip.com from Group2
Removing smtp:group2alias1@exoip.com from Group2
Removing smtp:group2alias@exoip.com from Group2
Removing smtp:group1new@exoip.com from Group1

I hope that this helped you to remove unwanted aliases from Microsoft 365 Groups.

Read more: Remove users from group with PowerShell »

Conclusion

In this article, you learned how to remove alias address from Microsoft 365 Group with PowerShell. Also, we showed how to bulk remove alias addresses from Microsoft 365 Groups to speed it up. Download the Remove-Alias-M365-Group.ps1 PowerShell script. Add the domain that you like to remove and run the script. The script output will show which alias addresses are removed. Don’t forget to test first with the -WhatIf parameter, as shown in the article.

Did you enjoy this article? You may also like Configure Azure AD Multi-Factor Authentication. Don’t forget to follow us and share this article.

ALI TAJRAN

ALI TAJRAN

ALI TAJRAN is a passionate IT Architect, IT Consultant, and Microsoft Certified Trainer. He started Information Technology at a very young age, and his goal is to teach and inspire others. Read more »

This Post Has 0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *