Microsoft Office 365 offers a truly great experience for hosting your e-mails. If you have small company adding domain and multiple different email addresses to every single person is easy enough and shouldn't take much time. However things get a bit complicated if you've got lots of people to handle (even 30 is a lot) and you have to add multiple combinations of email templates for each domain you support.

If you have Exchange On-Premise and Office 365 in Hybrid Scenario you can use On-Premise Exchange to create all your Email Address Policies. If you're just having Office 365 you have to either go thru PowerShell or do things manually. Below you can find a script which is supposed to simplify this a lot. I'll try to update it if there will be some interest.

Script Parameters

Script has multiple customization options that you can use during setup. It takes few parameters such as EmailTemplate, Commit, ExcludeUsers, ShowSummaryTable, ShowSummaryLines.

EmailTemplate – uses known to Microsoft Exchange products usage of %g (given name/first name) and %s (secondary name/last name) variables. So if we want to add all users on Office 365 online a new email template we can use combinations just like in standard Exchange Console. Feel free to explore possibilities. Generally script should cover most uses.

Commit – $true/$false (default $false) – is required to add new emails to existing users
ExcludeUsers – takes UPN (UserPrincipalName) and allows excluding of users that shouldn't be touched. Takes multiple UPN's. UPN's are also used to find mail accounts and match it with users.
ShowSummaryTable – $true/$false (default $true) – shows summary table
ShowSummaryLines – $true/$false (default $true) – shows summary lines

Additional fields are required to connect to Exchange Online (Connect-Ex function). Those are:

Login – is required to connect to online Exchange, user with administrative rights on Office 365 in form of email address

Password – is required to connect to online Exchange

SessionName – is optional but can be used to distinguish multiple Exchange connections

Script Usage

Usually usage should be something like this::

  • Connect to Exchange Online
  • Add 3 different types of email templates to users
  • Disconnects from Exchange Online

Example output:

Or something different:

Feel free to put your $login and $password directly in text form into script as it should be parsed correctly.

Script References

Function Remove-StringLatinCharacters – Non-latin characters in FirstName and LastName are replaced for easy generation of e-mails such us Przemysław Kłys will be converted to Przemyslaw Klys as Exchange wouldn't like it. 

Function Write-Color – allows for nice display of colors on one or multiple lines

Function Connect-Ex – allows to connect to Exchange Online remotely. It also allows to connect to On-Premise Exchange if parameters are given properly.

Function Disconnect-Ex – disconnects Exchange Online (or on-premise version).

PowerShell Script Code

Notes

This is a unique website which will require a more modern browser to work! Please upgrade today!