How to remove secondary e-mail addresses and external e-mail addresses

scorpio66
scorpio66 used Ask the Experts™
on
I am currently managing an Exchange 2007 organization and would like to know if there is a way (i.e. script) to remove secondary e-mail addresses and external e-mail addresses from the mail user accounts?  All of these accounts are under the Mail Contact container under Recipient Configuration.  I have been using the Exchange Management Console to do this task but I have no time to do it on thousands of accounts.  Any powershell guru out there?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
System Architect
Commented:
This might also do it... you would want to modify the 6th line to be LIKE the addresses you want to remove:

http://powershell.com/cs/media/p/3966.aspx
try this script

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 "*_site*" )
            {
                  Write-host("Remove smtp adress: " + $address.AddressString.ToString() )                  

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

        Set-Mailbox -Instance $_
}
 
Cheers

Author

Commented:
@Enphyniti
I should have added this info.  These are not local mailboxes but external mail accounts hosted on a different mail server.  I do not want to affect all of our local mailboxes and that is why I specified that these account are all under the Mail Contact container under the Recipient Configuration.  Will the above scripts work or is it only for local mailboxes?  I appreciate your response.
Jon BrelieSystem Architect

Commented:
Do you want to remove the contact, or just addresses from the contact?

Author

Commented:
Just the addresses.
Jon BrelieSystem Architect

Commented:
In that case, take a look at this thread.  You might be able to do this with Powershell based off the example provided.  Otherwise the latest version of ADModify could work as well.

Author

Commented:
Thanks Enphyniti.  I will give this a shot.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial