locked
Edit Bulk Mail Contacts RRS feed

  • Question

  • Hi, l am trying to remove additional SMTP addresses in bulk from Mail contacts in 2010 with the script below.

    $list = import-csv d:\support\contacts.csv
    foreach($Contact in $list)
    {
       $Contact.EmailAddresses |
       ?{$_.AddressString -like "@DOMAINNAME"} | %{
             Set-MailContact $Contact -EmailAddresses @{remove=$_}
        }
    }

    Contents of the contacts.CSV: has a header of Contact and list of External Email Addresses. 

    Wednesday, November 18, 2015 5:22 PM

Answers

  • Hi Lynn-Li,

    I took a look at your script and it looks good but was a bit unsure about the line "$contacts = Get-MailContact $list_.contact" so tested it out and found that it in fact gets all the Mail Contacts in my environment rather than just the ones in my CSV.

    If you change the line to be "$list | % {$Contacts += Get-MailContact $_.Contact}", this loops through all the contacts in the CSV and adds them to the $Contacts array. The full script is below:

    $list = Import-Csv D:\support\contacts.csv
    
    $Contacts = @()
    
    $list | % {$Contacts += Get-MailContact $_.Contact}
    
    foreach($Contact in $Contacts)
        {  
            $Contact.EmailAddresses | ? {$_.AddressString -like '*@litwareinc-sales.com'} | % {Set-MailContact $Contact -EmailAddresses @{remove=$_}} 
        }
    

    The CSV needs to only have a single column called Contact.

    Richard - please test and let us know if we've solved your issue.

    Thanks.


    Please mark as an answer if this answers your question

    Mark Gossa

    MCSE 2003, MCITP Enterprise Administrator 2008 R2, MCSA 2012 R2, MCTS Exchange 2010, MCTS SQL 2012, MCTS SharePoint 2007, VCP4, VCP5, CCNA

    Blog: http://markgossa.blogspot.com   LinkedIn:

    Posts are provided “AS IS” without warranty of any kind, either expressed or implied.

    • Marked as answer by Richard Lavery Friday, November 20, 2015 12:08 AM
    Thursday, November 19, 2015 8:29 PM

All replies

  • Hello Richard,

    Rather than going with Script, I would recommend you to try ADModifer Tool.

    https://admodify.codeplex.com/    Tool

    http://www.msexchange.org/articles-tutorials/exchange-server-2003/tools/ADModify-Change-Exchange-Specific-AD-User-Attributes.html   

    Follow the above article will help you using this tool.

    Regards,

    Praveen

    ----------------------------------------------------------------------

    Remember to mark as helpful if you find my contribution useful or as an answer if it does answer your question.That will encourage me - and others - to take time out to help you Check out my latest blog posts @ Techrid.com

    • Proposed as answer by SantoshE Sunday, December 13, 2015 7:41 AM
    Wednesday, November 18, 2015 7:36 PM
  • looks good.

    Please mark as an answer if this answers your question .

    PREM RANA

    MCSE Exchange 2013, MCSA 2012 Server MCTS Exchange 2007,

    2010, MCITP Exchange 2007, 2010 MCSE 2003 Server,

    MCSA Exchange 2003 ITIL V3 Foundation

    https://ranaprem.wordpress.com/

    This posting is provided AS IS with no warranties and confers no rights.

    Thursday, November 19, 2015 3:44 AM
  • Hi,

    There is no AddressString header in your contact.csv file, that's why this script doesn't work. If the following command is what you want, then try it.

    $list = import-csv d:\support\contacts.csv

    $contacts = Get-MailContact $list.contact

    foreach($Contact in $contacts){ 

    $Contact.EmailAddresses | ?{$_.addressstring -like '*@domain.com'} | %{ Set-MailContact $Contact -EmailAddresses @{remove=$_}   

    }

    }

    Original script get the value of addressstring parameter from Get-Mailbox, if you run the following command, you will understand.

    Get-MailContact contact | FL *address*

    Best Regards.


    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com

    Lynn-Li
    TechNet Community Support



    • Edited by Lynn-Li Friday, November 20, 2015 1:07 AM Edit script
    Thursday, November 19, 2015 7:59 AM
  • Hi Lynn-Li,

    I took a look at your script and it looks good but was a bit unsure about the line "$contacts = Get-MailContact $list_.contact" so tested it out and found that it in fact gets all the Mail Contacts in my environment rather than just the ones in my CSV.

    If you change the line to be "$list | % {$Contacts += Get-MailContact $_.Contact}", this loops through all the contacts in the CSV and adds them to the $Contacts array. The full script is below:

    $list = Import-Csv D:\support\contacts.csv
    
    $Contacts = @()
    
    $list | % {$Contacts += Get-MailContact $_.Contact}
    
    foreach($Contact in $Contacts)
        {  
            $Contact.EmailAddresses | ? {$_.AddressString -like '*@litwareinc-sales.com'} | % {Set-MailContact $Contact -EmailAddresses @{remove=$_}} 
        }
    

    The CSV needs to only have a single column called Contact.

    Richard - please test and let us know if we've solved your issue.

    Thanks.


    Please mark as an answer if this answers your question

    Mark Gossa

    MCSE 2003, MCITP Enterprise Administrator 2008 R2, MCSA 2012 R2, MCTS Exchange 2010, MCTS SQL 2012, MCTS SharePoint 2007, VCP4, VCP5, CCNA

    Blog: http://markgossa.blogspot.com   LinkedIn:

    Posts are provided “AS IS” without warranty of any kind, either expressed or implied.

    • Marked as answer by Richard Lavery Friday, November 20, 2015 12:08 AM
    Thursday, November 19, 2015 8:29 PM
  • Worked a treat, thanks Mark.
    Friday, November 20, 2015 12:09 AM
  • Hi, Mark Gossa.

    Thanks for pointing out.

    I forgot to remove underline in line "$contacts = Get-MailContact $list_.contact"

    I edited my script.

    Anyway, I am glad to hear that it worked.

    Best Regards.


    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com

    Lynn-Li
    TechNet Community Support

    Friday, November 20, 2015 1:06 AM