PowerShell script to export and import legacy Exchange x500 addresses (Manual)

When you’re migrating from one Exchange environment to another, or from on-premise to Exchange online without using the hybrid setup, the most forgotten part is the migration of the users x500 address. The reason why this is so important is because Exchange uses this to deliver local emails instead of the SMTP address that is normally associated with email. (This also goes along for calendar appointments)

So, by not migrating the x500 address it means that communications will fail when changing calendar appointments, or replying on old emails. To prevent this we will need to export the ExchangeLegacyDN from Active Directory, and import it again as a ProxyAddress in Active Directory.

Export the x500 address (ExchangeLegacyDN)

Step 1: From your source Active Directory, look up the distinguishedName, and copy the content of the value.

Step 2: Now copy the value from distinguishedName in to the script below, and run it on a domain controller. (adjust the export path if needed)

Import-Module ActiveDirectory

Get-ADUser -SearchBase “OU=2azure,DC=domain,DC=local” -Filter * -Properties SamAccountName,legacyExchangeDN | Select-Object SamAccountName,legacyExchangeDN | Export-CSV "C:\2azure\UserExport.csv" -NoTypeInformation 

Step 3: Now we will use the exported file to create an extra Proxy address for each user. So on the target domain controller run the following script.

Import-Module ActiveDirectory 

$import=Import-Csv "C:\2azure\UserExport.csv" 

foreach ( $user in $import)
{
if ($user.legacyExchangeDN){ 
$x500= "x500:" + $user.legacyExchangeDN 

Get-ADUser $user.SamAccountName | set-aduser -Add @{Proxyaddresses="$x500" }
}
}

Once completed, you should see the address in proxyaddresses under the user attributes. This should start with x500:

Leave a Reply

Your email address will not be published. Required fields are marked *