Remove all Secondary Email Addresses for Mailboxes

Introduction

This script will remove all Secondary Email Addresses for the Mailboxes.

Scenarios

This script is to help Exchange Admins to quickly remove all Secondary Email Addresses for Mailboxes via PowerShell.

Script

This script contains one advanced function Remove-OSCSecondaryEmailAddress, you can use this script in the following ways:

Step1: Run the script in the Exchange Management Shell, type the one command: Import-Module <Script Path> at the prompt.

For example, type Import-Module C:\Script\RemoveSecondaryEmailAddress.psm1

Here are some code snippets for your references.

PowerShell
Edit|Remove
Foreach($mbx in $Name){ 
    $Check = Get-Mailbox $mbx -ErrorAction SilentlyContinue 
    if($Check){ 
        #Get the primary Smtp Address 
        $PrimarySMTPLocal = $Check.PrimarySmtpAddress.Local 
        $PrimarySMTPDomain = $Check.PrimarySmtpAddress.Domain 
        #Remove all Secondary Smtp Address for that Mailbox 
        Set-Mailbox $mbx -Emailaddresses $PrimarySMTPLocal"@"$PrimarySMTPDomain 
        Write-Host "All Secondary Email Addresses for Mailbox $mbx had been removed."}

Examples

Example 1: Remove all SecondaryEmailAddresses for mailbox "Test1".
Command: Remove-OSCSecondaryEmailAddress -Name "Test1"
Screenshot:

Example 2: Remove all SecondaryEmailAddresses for mailbox "Test1","Test2".
Command: Remove-OSCSecondaryEmailAddress -Name "Test1",”Test2”
Screenshot:

Prerequisite

Exchange 2010 and above Exchange Version
PowerShell 2.0