Change User Profile Synchronization Connection without Losing Profile Data

Posted: Keith | Comments: 0 | July 14th, 2011
Jul 14

Recently we were dealing with an issue where users were imported from Active Directory into SharePoint User Profiles using the first part of the Fully Qualified Domain Name instead of the NetBIOS Domain Name. This creates issues with the User Profiles, specifically with the Organizational Browser. It appears there is a simple fix by setting the “NetBiosDomainNamesEnabled” property of the User Profile Service Application (UPA) to “True”. You can find several examples of how to do this on the web, but simply put:

$sa = Get-SPServiceApplication –Identity <UPA GUID>
$sa.NetBiosDomainNamesEnabled="True"
$sa.update()

After this is completed, you must create a new synchronization connection. Be aware, in our experience, deleting an existing connection will purge your existing profiles. That works great if done before any profiles have been updated. Our issue was what to do to apply this same fix but preserve existing profiles and their information. The fix? A combination of enabling NetBiosDomainNames on the UPA and resetting Profile Synchronization using PowerShell. First, the situation: We have a profile store with over 2000 profiles in it. Approximately 800 of which have been updated by end users. Due to a previous issue with the UPA, this is the second incarnation of the UPA at this client. Unfortunately after this one was created the synchronization connection was created before the NetBiosDomainNamesEnabled property was flipped. Now we had new profiles coming into the UPA with the first part of the FQDN instead of the NetBIOS name.

You can find the link to TechNet on how to “Reset Profile Synchronization by using Windows PowerShell” here.  This is part of bigger article on maintaining the SharePoint 2010 Profile Synchronization.

Here is the TechNet article verbatim:

Reset profile synchronization

The User Profile Synchronization database serves as a staging area for user profile information. User Profile information that is stored in the profile store and synchronization database is consumed by the User Profile service. By following the below steps, you can safely reset a User Profile Synchronization database without losing information in the profile store.

To reset profile synchronization by using Windows PowerShell
  1. Verify that you meet the following minimum requirements:
    • See Add-SPShellAdmin.
    • You must be a member of the Farm Administrators group on the computer that is running the SharePoint Central Administration Web site.
    • The farm account, which is created during the SharePoint farm setup, must also be a Local Administrator on the server where the User Profile Synchronization service is deployed.

      This is required to start the User Profile Synchronization service. After the User Profile Synchronization service is started you can remove the farm account from the Administrators group.

  2. As a precaution, back up the User Profile service application. For more information, see Back up a service application (SharePoint Server 2010).
  3. If you are using the My Site cleanup timer job, you must disable it before you reset the synchronization database. Otherwise, the job will delete all user profiles and My Sites from the farm. For information about this timer job, see the Timer job reference (SharePoint Server 2010). For information about the Windows PowerShell cmdlets that you use to enable and disable this timer job, see Timer jobs cmdlets (SharePoint Server 2010).
  4. On the Start menu, click All Programs.
  5. Click Microsoft SharePoint 2010 Products.
  6. Right-click SharePoint 2010 Management Shell and then click Run as administrator.
  7. In the User Account Control dialog box, click Yes.
  8. At the Windows PowerShell command prompt, type the following command to stop the SharePoint 2010 Timer service:

    Copy Code

    net stop sptimerv4
  9. Copy the following code and paste it into a text editor, such as Notepad:

    Copy Code

    $syncdb=Get-SPDatabase <SyncDBGUID>
    $syncdb.Unprovision()
    $syncdb.Status='Offline'
    $upa=Get-SPServiceApplication <UPSAppGUID>
    $upa.ResetSynchronizationMachine()
    $upa.ResetSynchronizationDatabase()
    $syncdb.Provision()
  10. Replace the following placeholders with values where:
    • <SyncDBGUID> is the GUID of the synchronization database.
    • <UPSAppGUID> is the GUID of the User Profile Service application.

    For more information, see Get-SPDatabase.

  11. Save the file as an ANSI-encoded text file and name the file ResetSyncDB.ps1.
  12. At the Windows PowerShell change to the directory where you saved the file.
  13. Type the following command:

    Copy Code

    ./ResetSyncDB.ps1
  14. Using SQL Server Management Studio, create a login in SQL Server for the User Profile Synchronization service account (that is, the farm account). Then, in the Sync database, create a database user that maps to the login and grant it access to the db_owner database role. For more information, see How to: Create a SQL Server Login (http://go.microsoft.com/fwlink/?LinkId=211993), How to: Create a Database User (http://go.microsoft.com/fwlink/?LinkId=211994), and Database-Level Roles (http://go.microsoft.com/fwlink/?LinkId=211995).
  15. At the Windows PowerShell command prompt, type the following command to start the SharePoint 2010 Timer service:

    Copy Code

    net start sptimerv4
  16. Start the Profile Synchronization service. For more information, see the Start the User Profile Synchronization service section of the "Configure profile synchronization" topic.
  17. Reset IIS. For more information about how to reset IIS, see the Reset IIS section of the "Configure profile synchronization" topic.
  18. See Below

Here are some addendums to this for our use:

In Step #9, we modified the script to find the User Profile Service Application

$syncdb = Get-SPDatabase | where {$_.name -eq "User_Profile_Service_Application_Sync_DB"}

$syncdb.Unprovision() $syncdb.Status=‘Offline’

$upa = Get-SPServiceApplication | where {$_.name -eq "User Profile Service Application"}

$upa.ResetSynchronizationMachine()

$upa.ResetSynchronizationDatabase()

$syncdb.Provision()

  • Replace with the name of your sync DB and your UPA.
  • This script does not show any status or progress, so you may adjust your script to show you it is working.

    ResetProfileSync

We did not find step #14 necessary.

Step #17 is not necessary if your UPA is on a different server than your Central Admin.

Now make sure you flip the property on the UPA:

  1. Copy the following code and paste it into a text editor, such as Notepad:
    $upa = Get-SPServiceApplication | where {$_.name -eq "User Profile Service Application"}
    $upa.NetBiosDomainNamesEnabled = "True"
    $upa.Update()
  2. Replace with the name of your UPA.
  3. Save the file as ANSI-encoded text file and name the file EnableNetBiosDomainNames.ps1
  4. At the Windows PowerShell, type the following command:
    .\EnableNetBiosDomainNames.ps1

    Notice there are now no Synchronization Connections:

    EnableNetBiosDomainNames

Step # 18 in the TechNet Article:

18.  Create connections to the data sources. For more information, see Restore a service application (Search Server 2010).

Run a full profile synchronization.  For more information, see Perform a nonrecurring profile synchronization.

I would recommend a full crawl on your search service application as well to make sure all People results are accurate.

This seems to have worked well for us and allowed us to clean up our UPA. I hope it works well for you too.

Leave a Comment