Powershell Script to Remove Mail Addresses

If you have migrated to Exchange 2007 or Exchange 2010 from legacy versions, and changed shared smtp namespaces, then unused mail address attributes will remain on migrated user objects.

Following script will read users.txt and look for specific text in mail addresses , and then will remove finally.

Get-Content C:users.txt |Get-Mailbox | foreach{   

    for ($i=0;$i -lt $_.EmailAddresses.Count; $i++)
    {
        $address = $_.EmailAddresses[$i]

        if ($address.IsPrimaryAddress -eq $false -and $address.SmtpAddress -like "*YOURTEXT*" )
        {
            Write-host("Remove smtp adress: " + $address.AddressString.ToString() )           

            $_.EmailAddresses.RemoveAt($i)
        }
    }   

        Set-Mailbox -Instance $_
}

Leave a Reply

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

1 + 3 =