locked
Adding additional SMTP address for new domain. RRS feed

  • Question

  • I've added a new domain to my exchange environment and modified the default policy to add an SMTP address for the new domain. For example, the PrimarySmtpAddress is user1@domain.com and the policy adds user1@newdomain.com as an additional SMTP address which allows the user to receive email sent to either address.

    However we have several users that have multiple addresses. For example, user1 may have user1@domain.com, u@domain.com, yourmom@domain.com, etc... For each of these additional addresses, I need to also add a corresponding address for newdomain.com. Any address @domain.com should also have an address @newdomain.com (user1@newdomain.com, u@newdomain.com, yourmom@newdomain.com)

    How can I automate this task using EMC or EMS?

    Tuesday, August 2, 2011 7:30 PM

Answers

  • here you go. This is Exchange 2010 version

     

    # Add proxy addresses
    # change the Get-Mailbox statement in line 8 to select only a subset of mailboxes
    
    $AddressSearchedFor = "*@domain.com"
    $DomainToAdd = "@newdomain.com"
    
    #get mailboxes and iterate through
    Get-Mailbox -ResultSize Unlimited | foreach{
     $_.Alias
     # .emailaddresses returns array
     # loop each email address
     for ($i=$_.EmailAddresses.Count;$i -ge 0; $i--)
     {
     $address = $_.EmailAddresses[$i]
     #Write-Host $address
     
     # look for SMTP addresses in source
     if ($address.SmtpAddress -like $AddressSearchedFor )
     {
     # get the left part of address
     $a = [string] $address
     $b = $a.indexof("@")
     $a = $a.substring(5, $b-5 )
     #Write-Host $
     
     # Add SMTP address
     Write-host("Adding smtp adress: " + $a + $DomainToAdd )
     # add address in the array
     $_.EmailAddresses.add("smtp:" + $a + $DomainToAdd)
     }
     # save changes
     $_ | Set-Mailbox -EmailAddresses $_.EmailAddresses
     }
     Write-Host
    }
    
    

     


    lasse at humandata dot se, http://anewmessagehasarrived.blogspot.com

    • Proposed as answer by Jason LJS Thursday, August 4, 2011 7:05 AM
    • Marked as answer by waskomatic Thursday, August 4, 2011 2:34 PM
    Wednesday, August 3, 2011 5:07 AM

All replies

  • If those extra addresses (u@domain.com) have been added manually, you probably dont have any attribute to create a policy to give them users a corresponding u@newdomain.com address.

    I would go for a EMS script to do this.

     


    lasse at humandata dot se, http://anewmessagehasarrived.blogspot.com
    Tuesday, August 2, 2011 10:31 PM
  • I was afraid of that...

    Any suggestions on an EMS script? I'm fairly new to EMS and not sure how to make this work. The problem I'm having is that all the additional email addresses are in a single comma delimted attribute. I'd sure appreciate any help on getting a script built.

    Thanks.

    Wednesday, August 3, 2011 3:47 AM
  • What version of Exchange is this?
    lasse at humandata dot se, http://anewmessagehasarrived.blogspot.com
    Wednesday, August 3, 2011 3:54 AM
  • We're in the process of migrating to 2010, but most of our users are still on 2007.

    Wednesday, August 3, 2011 4:15 AM
  • how many users you have like that?

     

    -bpara

    Wednesday, August 3, 2011 5:05 AM
  • here you go. This is Exchange 2010 version

     

    # Add proxy addresses
    # change the Get-Mailbox statement in line 8 to select only a subset of mailboxes
    
    $AddressSearchedFor = "*@domain.com"
    $DomainToAdd = "@newdomain.com"
    
    #get mailboxes and iterate through
    Get-Mailbox -ResultSize Unlimited | foreach{
     $_.Alias
     # .emailaddresses returns array
     # loop each email address
     for ($i=$_.EmailAddresses.Count;$i -ge 0; $i--)
     {
     $address = $_.EmailAddresses[$i]
     #Write-Host $address
     
     # look for SMTP addresses in source
     if ($address.SmtpAddress -like $AddressSearchedFor )
     {
     # get the left part of address
     $a = [string] $address
     $b = $a.indexof("@")
     $a = $a.substring(5, $b-5 )
     #Write-Host $
     
     # Add SMTP address
     Write-host("Adding smtp adress: " + $a + $DomainToAdd )
     # add address in the array
     $_.EmailAddresses.add("smtp:" + $a + $DomainToAdd)
     }
     # save changes
     $_ | Set-Mailbox -EmailAddresses $_.EmailAddresses
     }
     Write-Host
    }
    
    

     


    lasse at humandata dot se, http://anewmessagehasarrived.blogspot.com

    • Proposed as answer by Jason LJS Thursday, August 4, 2011 7:05 AM
    • Marked as answer by waskomatic Thursday, August 4, 2011 2:34 PM
    Wednesday, August 3, 2011 5:07 AM
  • I've done some testing and I think this is going to work for my purposes. However, there are a few users who already have the @newdomain addresses so I need to include an exception so it does not error out trying to add an address that already exists.

    Thank you!!

    Wednesday, August 3, 2011 6:14 PM
  • Hi,

    You need to add a loop before "# add address in the array" to compare all the smtp address in the mailbox account with the "$a + $DomainToAdd"


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    • Marked as answer by waskomatic Thursday, August 4, 2011 3:07 PM
    • Unmarked as answer by waskomatic Thursday, August 4, 2011 3:07 PM
    Thursday, August 4, 2011 7:14 AM
  • If users already have the @newdomain.com address, script will throw an error and continue.

    If you have many users you can change the line with Get-Mailbox to narrow down the scope of users to add addresses on.
    This will allow you to scroll up in the EMS window to see what happended during the run of the script.

     


    lasse at humandata dot se, http://anewmessagehasarrived.blogspot.com
    Thursday, August 4, 2011 10:10 AM