SP2013 ADImport | More than one DN specified for the same profile

I had an interesting issue where customer used ADImport to fetch the profile from AD to SharePoint. They had requirement to use Target audience functionality and when they look the "Manage Audience" in user profile service application, it shows only 5 users for a AD group where they have 186 users are part of this group in AD. 

Had a look at the ULS while Full import and found following exception which talks about the account duplication in DNLookup table. 

OWSTIMER.EXE(SERVERNAME:0x192C) 0x12D4 SharePoint Portal Server User Profiles c8hz Verbose ProfileImportExportService.UpdateWithProfileChangeData: Begin Add 'Domain\User'  

OWSTIMER.EXE (SERVERNAME:0x192C) 0x12D4 SharePoint Portal Server User Profiles aer4e Medium Exception while updating properties for 'Domain\User': Property: Url, Exception Microsoft.Office.Server.UserProfiles.PropertyNotDefinedException: Property Not Defined: Url. An administrator must create this property in the Profile Administration tool. at Microsoft.Office.Server.UserProfiles.UserProfile.get_Item(String strPropName) at Microsoft.Office.Server.UserProfiles.UserProfile.GetProfileValueCollection(String propName) at Microsoft.Office.Server.UserProfiles.UserProfile.BulkPropertiesUpdate(Int64 importExportId, Hashtable properties, String strAccountName).  

OWSTIMER.EXE (SERVERNAME:0x192C) 0x12D4 SharePoint Portal Server User Profiles aer4e Medium Exception while updating properties for 'Domain\User': Property: Description, Exception Microsoft.Office.Server.UserProfiles.PropertyNotDefinedException: Property Not Defined: Description. An administrator must create this property in the Profile Administration tool. at Microsoft.Office.Server.UserProfiles.UserProfile.get_Item(String strPropName) at Microsoft.Office.Server.UserProfiles.UserProfile.GetProfileValueCollection(String propName) at Microsoft.Office.Server.UserProfiles.UserProfile.BulkPropertiesUpdate(Int64 importExportId, Hashtable properties, String strAccountName).  

OWSTIMER.EXE (SERVERNAME:0x192C) 0x12D4 SharePoint Portal Server User Profiles aer4e Medium Exception while updating properties for 'Domain\User': Property: MailNickName, Exception Microsoft.Office.Server.UserProfiles.PropertyNotDefinedException: Property Not Defined: MailNickName. An administrator must create this property in the Profile Administration tool. at Microsoft.Office.Server.UserProfiles.UserProfile.get_Item(String strPropName) at Microsoft.Office.Server.UserProfiles.UserProfile.GetProfileValueCollection(String propName) at Microsoft.Office.Server.UserProfiles.UserProfile.BulkPropertiesUpdate(Int64 importExportId, Hashtable properties, String strAccountName).  

OWSTIMER.EXE (SERVERNAME:0x192C) 0x12D4 SharePoint Portal Server User Profiles ogvr High User profile record of "FMI\013081" was changed by 'Domain\ServiceAccount'.  

OWSTIMER.EXE (SERVERNAME:0x192C) 0x12D4 SharePoint Portal Server User Profiles c8i0 Verbose ProfileImportExportService.UpdateWithProfileChangeData: End Add 'Domain\User' 

OWSTIMER.EXE (SERVERNAME:0x192C) 0x12D4 SharePoint Portal Server User Profiles aei8n High ProfileImportExportService.UpdateWithProfileChangeData: Uncaught exception for object '14307fbf-5f94-48c4-a1f4-db8c1b409b96 ('Domain\User')' - System.InvalidOperationException: More than one DN specified for the same profile. at Microsoft.Office.Server.UserProfiles.ProfileImportExportService.AddDNLookupTable(UserProfileApplicationProxy upaProxy, Guid partitionID, Int64 recordId, String objectType, String distinguishedName) at Microsoft.Office.Server.UserProfiles.ProfileImportExportService.<>c__DisplayClass26.<UpdateWithProfileChangeData>b__24(Int32 idx).

 

Possible Causes

1) They may haven't do a Full profile import via UPA after the UPA configuration.
2) Most of the users may create by custom code, Search or by using My Sites.
3) First they were using UPS and later changed to ADImport. For some reason the profiles got corrupted.

Resolution

1) Run following powershell command and make note of guid of UPSA. 
Get-SPServiceApplication 
2) Run following commands one by one. 
$u = Get-SPServiceApplication 
Set-SPProfileServiceApplication $u -GetNonImportedObjects $true # Here you will get the results for profiles 'IsImportedvalue = 0' from ProfileDB 
Ran Set-SPProfileServiceApplication $u -PurgeNonImportedObjects $true # This cmdlet will mark the profiles for deletion and need MySiteCleanup job to delete those which are marked for deletion. If MySite is part of one user that added in missing profile, the same job will delete those MySites as well. Here is the detailed implications while running My Site Cleanup job.
3) Run Incremental profile import. Query following against ProfileDB and we should get no results. 
select * from DNLookup where isimported !=1 # Make sure you have backup of profile database before running any queries against it. 
4) Go ahead and run Full profile Import, once the above query returns no result.

 Reference : https://technet.microsoft.com/en-us/library/ff608004(v=office.15).aspx 

Happy SharePointing :)