When onsite with a customer last week they were curious as to how they could create an Exchange Email Address Policy (EAP) with an underscore in it. This was because the option to use an underscore is not present within the Exchange graphical tools.
For the record, I'm personally not a fan of using special characters in any situation. I'm a simple creature and do not use underscores or the ilk when defining email addresses. For this example, we want to create the email addresses in the format of email@example.com.
Since the option was not present in the graphical interface, time to break out PowerShell!
In order to determine what PowerShell command to run, we can cheat (just a little) and use the wizard as a starting point. Let's run through the wizard and then tweak the output. The below EAP will be targeted to a custom attribute. Note that the focus of this post is to review the creation of the EAP itself, we can get into the application of that in a later post.
Running Exchange 2010 Email Address Policy Wizard
At the organization level in the Exchange management tool, create a new Email Address Policy. Specify the name and recipient types that are needed.
In this case custom attribute 1 is used as a condition. This is set to a non-existent value since the Wizard us just helping us with the PowerShell command. The EAP that we will use is going to be created in PowerShell later.
Then next we want to click add to chose the SMTP address format of the Email Address Policy.
Note that there is no option to chose an underscore in the below screenshot. The default selection is to use the alias.
Since we want to create the email addresses in the format of firstname.lastname@example.org, lets chose the closest option that matches.
Clicking next produces the typical %email@example.com .
In this example we are not applying the Email Address Policy. This is just being used to discover the underlying PowerShell.
Clicking next, will create the policy.
In the Final screen we can copy out the PowerShell command used.
The copied command is shown below:
Summary: 1 item(s). 1 succeeded, 0 failed.
Elapsed time: 00:00:11
New Address Policy 01
Exchange Management Shell command completed:
new-EmailAddressPolicy -Name 'Address Policy 01' -IncludedRecipients 'AllRecipients' -ConditionalCustomAttribute1 'Corp' -Priority '1' -EnabledEmailAddressTemplates 'SMTP:%g.%s@Tailspintoys.ca'
Elapsed Time: 00:00:11
Standing On The Shoulders Of Giants
Now that we have the basic syntax, all we have to do is to modify the name and format of the policy. Note that in the below example, the name and format of the Email Address was changed – the underscore was inserted.
New-EmailAddressPolicy -Name 'Underscore Policy' -IncludedRecipients 'AllRecipients' -ConditionalCustomAttribute1 'Corp' -Priority '1' -EnabledEmailAddressTemplates 'SMTP:%g_%s@Tailspintoys.ca'
Looks good, so time to execute in PowerShell:
The EAP was successfully created.
Reviewing Underscore EAP In Exchange Management Console
If we then review the new EAP in the graphical tool, we can see that the address format is correct.
However, if we try to edit the email address, there is no option as this is not recognised by the graphical interface.
If we need to make modifications to the format of the EAP, then it's back to PowerShell we go!