Easily add Hybrid email address to users that don’t follow e-mail address policy

When attempting to move a mailbox to Office 365 one of most common failures is due to the user not containing the hybrid email address. This is because this check box is unchecked and this is done because the user has a custom email address that does not follow the conventions of the email policy.

In other words, because the check box with the green arrow is unchecked, the email address with the red arrow is not created. The email address with the red arrow is the hybrid address. It’s form is mail alias@<tenant name>.mail.onmicrosoft.com An example would be bjones@xyz.mail.onmicrosoft.com

2015-02-17_13-28-01

This first powershell one liner will find all the mailbox users with this box unchecked and dump the results into a csv file.

Get-Mailbox -ResultSize Unlimited | Where {$_.EmailAddressPolicyEnabled -eq $False} |select Alias,PrimarySmtpAddress |export-csv -NoTypeInformation MailboxesPolicyUnchecked.csv

The second one I called “AddTenantHybridSMTP.ps1” and the contents of that script is below. Without this script you woudl have to hunt down each of these users and check the box, select apply, then un-check the box and then designating the non standard email as the default email address, then click apply again.(Whew, that’s a lot of clicking !)

This script just adds the hybrid address to the user.
You will want to change the tenant name to the appropriate value; I have it as XYZ.

$CSV = Import-CSV ./MailboxesPolicyUnchecked.csv
foreach ($entry in $CSV) {
$TenantEmail = $entry.alias + "@XYZ.mail.onmicrosoft.com"
set-mailbox $entry.PrimarySMTPAddress -EmailAddresses @{Add=$TenantEmail}
}

Enjoy!

UPDATE

I had an issue that some users didn’t have the hybrid address even though the “apply policy” was indeed checked.

Not sure why that happened and I don’t care (LOL)

The script below will find the users that do not have a hybrid email address; you would need to modify the red “bvhs” part to the customer’s tenant name

Get-Mailbox -ResultSize Unlimited -Filter "emailaddresses -notlike '*@xyz.mail.onmicrosoft.com'" |select alias,primarysmtpaddress |export-csv -NoTypeInformation UsersWithOUTHybrid.csv

In some ways, it’s better than my first script, which is…

Get-Mailbox -ResultSize Unlimited | Where {$_.EmailAddressPolicyEnabled -eq $False} |select Alias,PrimarySmtpAddress |export-csv -NoTypeInformation MailboxesPolicyUnchecked.csv

Because that only lists the users where the email policy is not applied…. But for some strange reason… there are users without the hybrid address but the policy is indeed checked.

Advertisements

About Mike

owner of blog
This entry was posted in Migration, Office 365, PowerShell. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s