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 “alias@tenant.mail.onmicrosoft.com” 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 ilantz.onmicrosoft.com, 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 *@tenant.mail.onmicrosoft.com (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 – John.Doe12345@tenant.mail.onmicrosoft.com.
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 – http://gallery.technet.microsoft.com/Office-365-Add-Exchange-14c7f0c3
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 !
ilantz
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?
Nevermind I figured it out π Thanks
Glad it worked out for you π
I got the same issue. Is it because the 0365 version changed. It seems nothing happen when i use the script.
I got Problem when using the script. Nothing happen too. Do u know why or is it because O365 keeps updating.
I guess I need to update the file and the post.
It’s not an actual script it’s just a function. Open it, and copy it to the exchange shell. Then you can use the command…
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.
my bad, forgot to remove the line after testing… the script is updated now. no need to change anything in the code.
Thanks for the feedback !
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 firstname.lastname@somepolicy.com) 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 @tenant.onmicrosoft.com email it adds to that user?
Thanks in advance and Toda
sorry for the late response. I’ve updated the script to match what you’ve asked and some better logging. check out version 1.3.
thanks for the feedback!
ilantz
Thanks a lot
highly appreciated
Sure. Let me know how it worked out.
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…
Hey Nathan, I’ve tried some workaround to make that split more general.. see if re-downloading the script worked better π
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 “*@newaytech.mail.onmicrosoft.com”}
line76
needs to be $tenant.mail.onmicrosoft.com
no?
Whoops. I’ll fix that
done. sorry about that π
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.
Example:
you are looking for all users that do not have this tenant domain
*@contoso.mail.onmicrosoft.com
yet when you are checking the users mailbox object you are looking
username@contoso.mail.onmicrosoft.com
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 “*@contoso.mail.onmicrosoft.com”
Hi John,
Thanks for the feedback and sorry for the late reply.
the script actually uses server side filter to get only results without *@contoso.mail.onmicrosoft.com using the -filter option. please see that you have the latest version.
you can also invited to fork/contribute on my github –
Thanks again !
ilantz
Is there anyway the script can be modified, if mail.onmicrosoft.com is found then don’t add another one with a random name?
The script should already handle that. The $filter variable is constructed so it will match *@tenant.mail.onmicrosoft.com which should be the values that would exist and filter any recipient with those email addresses out.
Thank you for the swift response. I have ran the script as it is with making any modifications and found that if @tenant.mail.onmicrosoft.com already exists the script outouts ‘ @tenant.mail.onmicrosoft.com is conflicting with a different recipient’ and then adds another mail.onmicrosoft.com with a random number (i.e. joe34345@tenant.mail.onmicrosoft.com)?
I’ll take a look. Could be that I’ve missed something in the logic.