I recently worked on a Exchange deployment where the business wanted to add a new Accepted Domain, update the E-mail Address Policy so the new domain was their primary SMTP address on all mailboxes.
So in good practice I thought I’d test before apply to every mailbox in the organisation, I identified a test mailbox called “User A” and added a custom attribute of “NewDomain”, Created a copy of the original policy filtered with the new custom attribute and applied the policy.
On checking the mailbox I found the new E-Mail hadn’t been applied, this was because the “Automatic update e-mail address based on e-mail policy” had been unchecked.
So i thought I needed to Identity which other mailboxes have been removed from the policy, by using PowerShell I was quickly able to establish this:
## Get Mailboxes where EAP isn't enabled
$Mailbox = Get-Mailbox | Where {$_.EmailAddressPolicyEnabled -like "False"}
Using the $Mailbox collection I could quickly identify how many mailboxes had been removed:
## Get Mailboxes count
$Mailbox.count
Using the collection I could then put back into the policy using the following:
## Update Mailbox to be in the EAP
ForEach ($ObjItem in $Mailbox)
{
Set-Mailbox $ObjItem.identity -EmailAddressPolicyEnabled $true
}
This will check the “Automatic update e-mail address based on e-mail policy” that had been unchecked.
The above was my working out the solution to re-enable the policy on mailboxes, however this could create large collections on the computer because as you’ll see from from my PowerShell I was getting the mailboxes and running a Where on the collection. The more efficient way is to use the –Filter, on the initial Get-Mailbox:
Get-Mailbox -Filter {EmailAddressPolicyEnabled -eq $False}
If your happy to process all at the same time the PowerShell can be simplified to a single line:
Get-Mailbox -Filter {EmailAddressPolicyEnabled -eq $False} | ForEach {Set-Mailbox $_ -EmailAddressPolicyEnabled $True}
Disclaimer: All scripts and other PowerShell references on this blog are offered "as is" with no warranty. While these scripts are tested and working in my test environment, it is recommended that you test these scripts in your own test environment before using in any production environment.
This comment has been removed by the author.
ReplyDelete