How to Reprovision User Profile Sync in SharePoint

Reprovision user profile sync is one of the last things I would try in an effort to get the SharePoint sync working. This has fixed sync issues many times. Recently, because of server version mismatch issue explained in this blog, user profile synchronization started throwing errors.

There are many articles in the internet when i searched for this error.

I tried many other options, like stopping and staring UPS and clearing the SharePoint cache. I also made sure that there is no issue with AD.

This issue surfaced only in one of many server farms. This made it clear that it has something to do with this server farm alone. Reprovisioning user profile sync solved many sync issues for me in the past. So, I have decided to give it a try.

As always, if you are working in Production farm, please backup Profile, sync and Social databases.

As a precautionary measure, it is a good idea to document synchronization connections, connection filters and any custom property mappings. Because at the end of the process, we need to reconfigure all these settings.

There are many other blogs written on the same process. I am writing it as a note for future myself to refer, next time I face anything like this. Here are the steps to follow to Reprovision User Profile Sync

  • Stop the SharePoint Timer Service in the App Server running UPS.
  • Stop User Profile Synchronization service through Central Administration. Central Admin > System Settings .Manage Services on Server > App Server > User Profile Synchronization Service and click Stop
  • Run the following PowerShell in SharePoint Management Shell with elevated permissions

    Get-SPDatabase | Out-File D:\Databases.txt

  • Open the databases.txt file and file the ID for Sync database.
  • Run the following PS commands to remove data in sync database

    $syncDataBase = Get-SPDatabase -Identity “GUID of Sync database”
    $syncDataBase.Unprovision()
    $syncDataBase.Status=’Offline’

  • Get the reference to User Profile service, reset and provision the sync database

    $ups = Get-SPServiceApplication -Name “User Profile Service”
    $ups.ResetSynchronizationMachine()
    $ups.ResetSynchronizationDatabase()
    $syncDataBase.Provision()

  • Verify that Farm admin account has access to sync database in SQL.
  • Start back the SharePoint Timer Service which we stopped in step 1.
  • Start back the User Profile Synchronization Service running in App Server. Central Admin > System Settings .Manage Services on Server > App Server > User Profile Synchronization Service and click Start.┬áThis might take 10-15 mins to start after you enter Farm admin credentials
  • Optional IISRESET
  • Open the User Profile Service Application under Central Admin > Application Management > Manager Service Applications. Configure the synchronization connections and Connection Filters.
  • Rebuilding your SyncDB or recreating connection to Active Directory will mark all user profiles for deletion after first full or incremental sync. Disable MySite Cleaner Timer job to prevent user profiles from getting deleted.
  • Configure any mappings to custom property mappings
  • Run Full Synchronization, twice to sync all the users.