header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Change multiple ExternalEmailAddress feilds at once.
Last Post 02 Jul 2009 09:56 AM by kpeakman. 6 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
kpeakmanUser is Offline
New Member
New Member
Posts:5
Avatar

--
01 Jul 2009 07:52 PM
    I am in a scenario where I need to change a couple thousand email addresses at once. We are running E2K7 across two seperate forest using MS Identity Integration to replicate contacts between forest. 

    I can filter down to the list of contacts that I need to have the ExternalEmailAddress changed for. I can then select all, then modify. However, this would change all of the ExternalEmailAddress for all of the contacts to the one static entry that I input.

    What I need, in short, is a script that allows me to to change the value of the ExternalEmailAddress utilizing the Alias for each contact. I've tried different variations of %m thinking it would pull the Alias for the record and reconstruct the ExternalEmailAddress field, but what I end up with is -
    SMTP:%m@mydomain.com

    I would think that I could use a Set-MailContact at the end of this:

    Get-MailContact | where { $_.'ExternalEmailAddress' -like '*@mydomain.com*' } | Select-Object -property 'Name', 'Alias', 'RecipientType', 'ExternalEmailAddress'

    But, I am having issues! Any assistance would be appreciated.
    Karl MitschkeUser is Offline
    Basic Member
    Basic Member
    Posts:451
    Avatar

    --
    02 Jul 2009 07:12 AM
    Try this one liner:

    Get-MailContact -Filter {ExternalEmailAddress -like '*@mydomain.com'}|Select-Object alias |ForEach-Object {Set-MailContact -Identity $_.alias -EmailAddresses($_.alias +"@mydomain.com")-WhatIf}

    Karl
    http://unlockpowershell.wordpress.com
    Co-Author, Windows PowerShell 2.0 Bible
    -join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
    kpeakmanUser is Offline
    New Member
    New Member
    Posts:5
    Avatar

    --
    02 Jul 2009 08:11 AM
    That looks like exactly what I need. However, when I try to run this without the -whatif statement, I get the error

    "The e-mail address for this recipient are automaticaly generated based on e-mail address policies. To modify the primary SMTP address for this recipient, you must disable automatic updating of e-mail addresses based on e-mail address policy".

    I've tried running: Get-MailboxServer | Get-Mailbox | Set-Mailbox -emailAddressPolicyEnabled $false

    But no luck there either.


    Karl MitschkeUser is Offline
    Basic Member
    Basic Member
    Posts:451
    Avatar

    --
    02 Jul 2009 08:18 AM
    Try this:

    Get-MailContact -Filter {ExternalEmailAddress -like '*@mydomain.com'}|Select-Object alias |ForEach-Object {Set-MailContact -Identity $_.alias -EmailAddresses($_.alias +"@mydomain.com") -emailAddressPolicyEnabled $false -WhatIf}

    http://unlockpowershell.wordpress.com
    Co-Author, Windows PowerShell 2.0 Bible
    -join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
    kpeakmanUser is Offline
    New Member
    New Member
    Posts:5
    Avatar

    --
    02 Jul 2009 09:26 AM
    It's so strange.. running the script with the -whatif seems to work great. I can see a list roll by of everyone showing this:

    What if: Setting Mail Contact "Nameofuser"

    But when I run the script without the -whatif part, I get tons of errors like the following:

    + Get-MailContact -resultsize unlimited -Filter {ExternalEmailAddress -like '*@mydomainA.com'}|Select-Object alias |ForEach-Object {Set-MailContact <<<<
    -Identity $_.alias -EmailAddresses($_.alias +"@mydomainB.com") -emailAddressPolicyEnabled $false }
    Set-MailContact : The operation could not be performed because 'CSmith' matches multiple entries.
    At line:1 char:141

    Now, I can understand the error message. Clearly, I have two users that have an Alias of 'CSmith' - But what is troubleing, is that I when I go into EMS, after the script finishes, and fliter down for the contacts that have an externalemailaddress that contains @mydomainB, there are none? The script fails.
    Karl MitschkeUser is Offline
    Basic Member
    Basic Member
    Posts:451
    Avatar

    --
    02 Jul 2009 09:36 AM
    That's my mistake;

    Try this:

    Get-MailContact -resultsize unlimited -Filter {ExternalEmailAddress -like '*@mydomainA.com'}|Select-Object alias |ForEach-Object {Set-MailContact -Identity $_.alias -emailAddressPolicyEnabled $false -ExternalEmailAddress ($_.alias +"@mydomainB.com") }
    http://unlockpowershell.wordpress.com
    Co-Author, Windows PowerShell 2.0 Bible
    -join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
    kpeakmanUser is Offline
    New Member
    New Member
    Posts:5
    Avatar

    --
    02 Jul 2009 09:56 AM
    YES! That's the one. I can't thank-you enough! :)
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer