how to bulk remove an email alias in Exchange 2016?

Sophia 356 Reputation points
2021-05-07T18:54:20.153+00:00

Hello guys/gals,

How would should I go about removing an email address alias for all of my mailboxes?

Currently mailboxes have the following:
SMTP:user1@mathieu.company .com
smtp:user1@mathieu.company .mail.onmicrosoft.com
smtp:user1@xyz .com (I want to remove this alias)
X400
x400
x500

Thanks,

Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
2,882 questions
Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
6,082 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Yuki Sun-MSFT 24,601 Reputation points
    2021-05-10T02:00:41.867+00:00

    Hi @Safs-3080,

    Based on my research and test, the following scripts can be used to bulk remove a secondary smtp email address.

    You can copy and paste the below code in Notepad, save it as a.ps1 file and give it a name such as "Remove-SMTP.ps1", put it in a folder like C:\scripts, then you would be able to bulk remove all SMTP addresses with the domain xyz.com by running the script. Before running the script, it's suggested to add "-WhatIf" after "Set-Mailbox $Mailbox -EmailAddresses @{remove = $_ } " to take a look at what will happen.

    Start-Transcript -Path C:\temp\Remove-SMTP-Address.log -Append  
    $Mailboxes = Get-Mailbox -ResultSize Unlimited  
       
    foreach ($Mailbox in $Mailboxes) {  
      
            $Mailbox.EmailAddresses | Where-Object { $_.AddressString -like "*@xyz.com" } | ForEach-Object {  
       
            Set-Mailbox $Mailbox -EmailAddresses @{remove = $_ }   
       
            Write-Host "Removing $_ from $Mailbox Mailbox" -ForegroundColor Green  
        }  
    }  
    Stop-Transcript  
    

    95069-1.jpg

    95007-2.jpg

    For more details, hopefully you can find the article below helpful:
    Bulk remove secondary SMTP address with PowerShell
    Please Note: Since the web site is not hosted by Microsoft, the link may change without notice. Microsoft does not guarantee the accuracy of this information.


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.