-->

Saturday, January 16, 2016

Exchange Adding X500 Legacy Addresses in Bulk

My company grows by acquisitions, which means we do a lot of Exchange migrations. Most of them are very slow, drawn out cut-overs where we have to create users in our Active Directory then migrate Exchange at a later date. Since these Exchange "migrations" aren't actually moving mailboxes and profiles, we end up a with a ton of outdated Outlook autocomplete entries causing internal mailflow bounces.

The easiest way to fix this is to have users empty their autocomplete cache in Outlook, but let's face it, you can't rely on users to do the right thing ;)

The other, more involved way to fix the problem is to add X500 Legacy Addresses to the mailboxes of users that are being migrated.

If you have several hundred users being migrated this can be a daunting task. Luckily, PowerShell is to the rescue!

Gathering the X500 Information:

**Note** The following process will require you to have rights/access on the Source Domain - the one you're moving users From.

On the Source domain, fire up an elevated Active Directory for Windows PowerShell, and run the following command:

Get-ADUser -SearchBase “OU=users,DC=domain,DC=com” -Filter * -Properties DisplayName,legacyExchangeDN | Select-Object DisplayName,legacyExchangeDN | Export-CSV C:\UserExport.csv -NoTypeInformation

**Note** Change “OU=users,DC=domain,DC=com” to the Distinguished Name of the OU in the domain you're moving from.

**Note** The following pertains to my environment, where we use "FirstName LastName" for the Display Name format. This requires some spreadsheet manipulation if we are migrating from "LastName, FirstName" - which is the most common convention.

Creating the CSV with X500 Info:

If the Display Names are Lastname, Firstname:

Once you have the CSV, you'll need to reverse the Last, First Name Order with this formula:

In Cell C2 enter:

=MID(A1&" "&A1,FIND(" ",A1)+1,LEN(A1)) and copy down to the end of the cells.

Copy the values only from Column C over to Column A.

Delete the entries in Column C.

Then find and replace to remove the commas.

Change Column A heading to Name, and change Column B to X500

Next, you'll need to add "X500:" to each legacyExchangeDN line with this formula:

In Cell C2 enter:

="X500:"&B2 and copy down to the end of the cells.

Copy the new X500 values from Column C over Column B

Delete the entries from Column C.

Save the newly formatted CSV with a name like AddX500.csv

Copy the .CSV to an Exchange Server in the Target Domain.

On the Exchange Server in the Target Domain, fire up the Exchange Management Shell and run the following cmdlet:

$CSV = Import-CSV "C:\Temp\Addx500.csv"

**Note** Change C:\Temp\Addx500.csv to the location that you copied the CSV to.

Then run:

$CSV | foreach {Set-Mailbox -Identity $_.name -EmailAddresses @{Add= $_.x500}}

Ignore or fix errors - some names will not match so those will have to be manually corrected.

Now when your newly migrated users mail each other, they won't get "user doesn't exist..." errors!

No comments:

Post a Comment