Handling pre-existing contacts before FIM/MIM Galsync begins


Contoso wants to setup Galsync with Fabrikam. Currently Contoso manually creates Fabrikam users as mail contacts in their Exchange organization. They do not really trust the data in the objects and while MIM will overwrite most of the data on join it will not overwrite all the attributes. They would like to

  1. Delete the Fabrikam contacts so that MIM can populate the attributes with fresh correct data from the Fabrikam AD.
  2. Maintain the legacyExchangeDN of the deleted contacts as an X500 address in the new contacts so that replies to old emails will still work.
  3. Set the LegacyexchangeDN to a standard format where the “CN=” in the LDN will be equal to the email address minus the “@”.


  1. MIM creates these new contacts as cross forest contacts and they are tagged as read only in Exchange, so you cannot update the proxyaddresses field with an Exchange function like Set-mailcontact.
  2. If you use set-ADObject to make the change to the contacts, MIM will change it back because these contacts belong to MIM and only MIM can change them.

Possible Solutions

Use File Connector

  1. Export the legacyexchangedn and email from the contacts before deleting them.
  2. Write a function in MA extension to insert the legacyexchangedn into the proxyaddresses in the Metaverse
  3. Use a File connector in MIM to import the exported data.
  4. Use attribute precedence (set it to equal) to trigger the insertion on sync of the legacyexchangeDN into the MV

Use PowerShell

  1. Export FN,LN,DN (remove any coma),Email,legacyexchangeDN
  2. Delete the contacts
  3. Create mailenabled contacts from the exported data. Add the old legacyexchangeDN to the MV proxyaddresses
  4. Import these contacts into MIM
  5. Import the Fabrikam users.
  6. Sync the data, MIM will join the objects and the new attributes will flow.

In writing this PowerShell script I noted a couple of things

  1. The Get-MailContact function does not get the firstname and lastname fields. For whatever reason Msft did not include these. If I use the Get-Contact function or Get-recipient function I get the FN and LN but not the legacyexchangeDN (LDN). So I had to use the Get-ADObject function.
  2. The New-MailContact function does not allow you to set the LDN to a specific format. Msft expects the RUS to set the LDN so that they did not include the option of setting the LDN in any Exchange function. The New-MailContact also does not allow the adding an address to the proxyaddresses attribute. So I have to use Set-ADObject to reset the LDN to the format I want and add the export LDN of the old contact to the proxyaddresses attribute.
  3. I ran the script in the Exchange Management Shell but I imported the ActiveDirectory module. For Exchange 2010 and greater make sure that the EMS loads PowerShell v4 on load.

Here is the script

#Export the FN,LN,DN,mail,LDN to file
Import-module activedirectory
$fileName = “C:\temp\Createcontact1.csv”
$fileObject = New-Item $fileName -type file -force
$evt_string | Out-file $fileObject -encoding ascii -Append
$Mycontacts=Get-ADObject -Filter * -searchbase “OU=FabrikanContactsOld,DC=tlkenterprise,DC=net” -properties givenname,sn,displayname,mail,legacyexchangedn
ForEach ($mycontact in $mycontacts){
If ($mycontact.legacyexchangedn -ne $null){
$evt_string=$mycontact.givenname + “,” + $mycontact.sn + “,” + $mycontact.displayName + “,” + $mycontact.mail + “,” + $mycontact.legacyexchangedn
$evt_string | Out-file $fileObject -encoding ascii -Append

#Delete the contact
Import-CSV c:\temp\createcontact1.csv | ForEach-Object {Remove-mailcontact $_.primarysmtpaddress -Confirm:$false}

#Create the contact with exported data – FN,LN,DN,mail,Name(CN)
Import-CSV c:\temp\createcontact1.csv | ForEach-Object {$pos=$_.primarysmtpaddress.replace(“@”,”.”); New-MailContact -Firstname $_.firstname -Lastname $_.Lastname -displayName $_.displayname -Name $pos -Alias $pos -ExternalEmailAddress $_.primarysmtpaddress -OrganizationalUnit “OU=FabrikanContactsNew,DC=tlkenterprise,DC=net”}

#Use Set-ADObject to change the LDN and add old LDN to proxyaddresses
Import-CSV c:\temp\createcontact1.csv | ForEach-Object {$myc = $_.primarysmtpaddress;$MyContact=Get-AdObject -Filter {mail -eq $myc} -searchbase “OU=FabrikanContactsNew,DC=tlkenterprise,DC=net”; $NewLDN=”/o=TLKEnterprise/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/cn=” + $MyContact.Name; $MyContact.legacyExchangedn= $NewLDN; Set-ADObject -instance $MyContact; Set-ADObject -identity $mycontact -add @{Proxyaddresses=”X500:”+$_.legacyexchangedn}}