Email Address Policies are bread and butter in Microsoft Exchange world. If you work with On-Premise Exchange 2007, Exchange 2010, Exchange 2013/2016 you most likely set it up more than once. Unfortunately if you're Office 365 Exchange Online Administrator and don't have On-Premise Exchange in Hybrid scenario to use, Microsoft doesn't give you any GUI option to do this except editing email addresses one by one.
Doing any modifications via PowerShell is also gonna set you back couple of hours as well. Recently we've been asked by customer with 20 accounts to create and manage on Office 365 with multiple domains and I didn't want to spend hours on manual labor creating it, I've decided to write a little script that does that for me. Hope you will find it useful in your scenarios.
Solution
Script takes similar approach known to Microsoft Exchange administrators and allows easy configuration of Email Address Policies based on templates.
- "%g.%[email protected]" # would give [email protected] - "%1g.%[email protected]" # would give [email protected] - "%1g%[email protected]" # would give [email protected] - "%3g.%[email protected]" # would give [email protected] - "%g.%[email protected]" # would give [email protected] - "%[email protected]" # would give [email protected]
Adding 3 new domains to Office 365 can be easy with few lines of code:
cls $login = Read-Host "Please enter your login (in form of email)" $password = Read-Host "Please enter your password" $sessionName = Read-Host "Please enter session name (leave blank for default)" Connect-Ex -login $login -Password $password -sessionName $sessionName Add-EmailAddressToUsersFromTemplate -EmailTemplate "%g.%[email protected]" -Commit $false -ExcludeUsers "[email protected]","[email protected]" Add-EmailAddressToUsersFromTemplate -EmailTemplate "%1g.%[email protected]" -ExcludeUsers "[email protected]" Add-EmailAddressToUsersFromTemplate -EmailTemplate "%1g%[email protected]" -ShowSummaryTable $true -ShowSummaryLines $true -Commit $true -ExcludeUsers "[email protected]","[email protected]","[email protected]" Disconnect-EX -sessionName $sessionName
Which should give similar input to one below
Full description of the script mimicking functionality of Email Address Policies can be found at Office365-AddBulkEmailAddresses.ps1