RSS
Twitter
LinkedIn

 

SharePoint 2013 - Migrate/Replicate User Profile Service Application Configuration between Farms using PowerShell - Part 1

I came across a requirement to quickly and easily create duplicate/matching ‘User Profile Service Application Configurations' between SharePoint Farms, when recently setting up SharePoint 2013 Dev, Staging and Production environments.

 

Assuming you have a working User Profile Service Application (or UPSA), with multiple Active Directory (AD) Sync Connections, on an existing farm. The following shows how you can take the settings of the existing UPSA and use them to create a new UPSA on a different/alternative SharePoint 2013 farm.

 

The first step is export the Active Directory Sync Connection configuration.

This can be achieved by establishing a connection to the UserProfileConfigManager.ConnectionManager and using the GetEnumerator method to retrieve and iterate through each data source connection in the current service context, before exporting them to an XML file using the Export-Clixml cmdlet.

 

For Example:

 

This should create an individual "UPSConnection_<AD_Sync_Connnection_Name>.xml" file for each Sync Connection found.

 

 

The second step (...if you haven't done so already) is to create a new ‘blank' User Profile Service Application on the target Farm.

 

This can be done via Central Administration or (preferably) via PowerShell...

 


(...or if you happen to use AutoSPInstaller for your Farm Builds then you can also use it to Provision Service Applications)

Whichever approach you choose, I would advise using the same across on each of the farms.

 

 

The next step is to import the Sync Connection configurations into the new/blank USPA.

Now there seems to two possible approaches available for creating new User Profile Sync Connections via PowerShell...

 

The Add-SPProfileSyncConnection Cmdlet (Removed from TechNet - Not Supported see Harbar.net )

vs.

The AddActiveDirectoryConnection method of the ConnectionManager

 

Now due to the various (well documented) limitations of the Add-SPProfileSyncConnection cmdlet (such as ‘not being able to set the DisplayName', ‘one connection per forest' and it ‘overwrites the ConnectionSynchronizationOU'), along with the fact we're already exporting the settings via the ConnectionManager, we need to opt for the AddActiveDirectoryConnection method.

 


 

 

Some of the advantages of using this 'Export / Import' approach is the ability to easily create the DirectoryServiceNamingContext from the XML file with a single line of PowerShell ...

 

...which can then be passed to the AddActiveDirectoryConnection method of the ConnectionManager

 

You can also easily change/verify the DisplayName of the Sync Connection via PowerShell...

 

...or via the exported XML configuration file property

 


As well as being able to select which OU Containers are ‘included' or ‘excluded' by the Sync Connection via the ‘ContainersIncluded' and ‘ContainersExcluded' properties in the exported XML configuration file

 

 


 

I've also put together the following scripts to achieve this via some easy to use PowerShell :

NOTE: Please download attached zip for "full/complete .ps1" files (plus additional Create UPS examples) - All examples provided above are simplified abbreviations

download  UserProfileServiceApp_PowerShell_ExportImportADConnections.zip

Usage:

  • .\ExportImport_UPSConnections.ps1 -MySiteURL http/https://<MySiteURL> -DoExport  ## Export All Connections ##
  • .\ExportImport_UPSConnections.ps1 -MySiteURL http/https://<MySiteURL> -DoExport -ExportConnectionName <SP_ADConnectionName> ## Export Specific Connection ##

  • .\ExportImport_UPSConnections.ps1 -MySiteURL http/https://<MySiteURL> -DoImport -ImportXMLFilePath <FullPathToXMLConnectionFile> -ConnectionPassword <ADConnectionPassword> ## Import Specific Connection ##

 

 

 

 

Comments

 

SharePoint 2013 Training said:

It's seems as of lately with SharePoint, recreating the User Profile Service Application is required after each installation

April 24, 2015 11:55 AM
 

Bruce said:

Gerat work! Thanks for sharing!

August 17, 2015 11:50 AM
 

Anna said:

Hi. I tried this and was able to export the UPSConn from SP2010 but i'm having difficulties in importing said connection to SP2013. Here's the error I encountered:

Exception calling "AddActiveDirectoryConnection" with "10" argument(s): "Could

not load file or assembly 'Microsoft.ResourceManagement, Version=4.0.2450.51,

Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.

The system cannot find the file specified."

At C:\ExportImport_UPSConnections.ps1:138 char:5

+     $newUPSADConnection =  $UPSConnMgr.AddActiveDirectoryConnection(

+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

   + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

   + FullyQualifiedErrorId : FileNotFoundException

November 2, 2016 1:00 AM