Manually adding a secondary SMTP proxy address for hybrid Exchange Online and Office 365

Update – 05-02-2015 – Thanks for the feedback about this post, some more work has been done, please download the new version…

Update – 07-30-2014 – Thanks for the feedback about this post, I’ve republished the code. it is now wrapped as a script and also logs results to a log file. download the new version…

I’ve been busy with more Office 365 and Hybrid Exchange Online deployments and came up with a script I hope will help some of you out there.

While deploying an Hybrid Exchange Online setup, one of the steps the Hybrid Configuration Wizard is doing is modifying the email address policy and adding “” to the relevant EAP policies. This is great although there’s a good chance you have some mailboxes that are set with EmailAddressPolicyEnabled:$false

I’ve written a function script that will help you add the additional secondary SMTP proxy address to those mailboxes easily ๐Ÿ™‚

Here’s an example on how to use the script:

.\Add-OnMicrosoftSMTP.ps1 -Tenant:ilantz

The script will require your “Tenant” name, for example – if your Office 365 tenant is, enter ilantz as the tenant name. Once entered it will find all mailboxes with the property EmailAddressPolicyEnabled:$false and have no routing SMTP address like * (following the default Exchange Hybrid Configuration Wizard settings).
Then the script will add the required SMTP proxy address following the PrimarySmtpAdress prefix, if that SMTP proxy address is already taken, the function will add a random 5 digit number to the prefix –

The script will catch and display any exceptions that may occur during the process. and will automatically log the results to a log file.

Get the script here –
Revision History

1.0 – Initial release

1.1 – Updated and rewritten as a script instead of a function which caused confusion

1.2 – Added Logging of successful addresses being added and failures

1.3 – Updated with server-side filtering to get all relevant users for better efficiency,
an updated logging mechanism and using now the PrimarySmtpAddress prefix value for the routing address.

Enjoy !


19 thoughts on “Manually adding a secondary SMTP proxy address for hybrid Exchange Online and Office 365”

  1. Hi there,
    So I tried loading the function in the exchange PowerShell using . .\Add-Onmicrosoftsmtp and then tried running it, but it still doesn’t do anything. Am I missing something?

  2. It really works great now ! It will generate a log by minute.

    Just a reminder to the one who run this script.
    un-remark line 81 and remark line 82, it will work nice.

    $users = get-mailbox -Filter {EmailAddressPolicyEnabled -ne $true}
    #####$users = get-mailbox Ilantz-onprem

    Thanks ilantz !!!

    This really save me a lot of time.

  3. Hi Ilan
    Thanks a lot for this script I was going to write something myself but then found this(much easier)I only have one question/request.
    in my case, I have a lot of mailboxes that don’t even follow the naming convention(let say how can I change the script so it just takes whatever is on the primary email address of the mailbox up to the @ sign and just makes it the same for the email it adds to that user?
    Thanks in advance and Toda

  4. Seeing all of the positive feedback, I’ll assume I’m the odd man out here – but I’ve unfortunately not had any success with the script. I keep getting the response (for each user), “Method invocation failed because [Microsoft.Exchange.Data.SmtpAddress] does not contain a method named ‘Split'”. Not sure what’s different about my environment from others, but — no go for me. :-\ Huge bummer as I’m having to manually update 1000+ addresses.. It’s exhausting…

  5. Hi ilan
    Thanks agin and toda for the primary address change
    but I think you have typo here(you forgot newway:))
    $users = get-mailbox -Filter {EmailAddressPolicyEnabled -ne $true -And EmailAddresses -notlike “*”}

    needs to be $


  6. Although the script works fine I found an issue it:
    You are filtering on anything that does not have the tenant domain yet further down in the foreach loop you are looking for that same tenant domain email address to add a random digit to the user portion of the primary address.
    you are looking for all users that do not have this tenant domain
    yet when you are checking the users mailbox object you are looking
    so you are adding a random number after the username if there is a conflict.
    Note that the all $user object collection as per defined filter should not include any users that have the proxy address that contain “*”

    1. Hi John,
      Thanks for the feedback and sorry for the late reply.
      the script actually uses server side filter to get only results without * using the -filter option. please see that you have the latest version.
      you can also invited to fork/contribute on my github –

      Thanks again !

Leave a Reply