ExchangeOffice 365

Add routing addresses without an email address policy

I came across an issue for a client today where 90% of the mailboxes were set to not inherit the email address policy from exchange. Furthermore the policy was different to the actual email addresses so I could not simply turn the policy on for the accounts to inherit the required routing addresses.

The company use but the policy was set to so bulk enabling the setting would have modified everyone’s reply address!

Normally I would edit the policy to match the required format (first.last) then enable it on the mailboxes, however this customer also has multiple primary email domains so this was difficult without multiple policies and scoping the policies to the correct mailboxes. The user accounts with the different primary email addresses were scattered amongst several OU’s which made scoping too challenging to use email address policies to achieve the task.

I turned to PowerShell to solve the problem

This was achieved by filtering out any accounts that already had the address as we didn’t want to end up with multiple different entries. Next the script injects the routing address using the @{add} method on the set-mailbox cmdlet to add the additional address without touching the primary or affecting any other addresses.

The script syntax is as follows

$allmailboxes = get-mailbox -resultsize unlimited
foreach ($mailbox in $allmailboxes){
if ($mailbox.emailaddresses -like "**") {
write-host $ "Has a 365 address...skipping...." -ForegroundColor Yellow
} else {
write-host $ " Does not have a address - adding..."
$OnMicrosoftAddress = $mailbox.alias + ""
set-mailbox $mailbox -EmailAddresses @{add=$OnMicrosoftAddress}
write-host "Added" -ForegroundColor Green

I am planning to build this out further to include more verbose reporting and a whatif mode before publishing it on the TechNet gallery.

365 Guy

Microsoft Infrastructure Consultant @ Novosco. Specialising in Office 365, Azure AD & Exchange Server.

Leave a Reply

Your email address will not be published. Required fields are marked *