Updating Sitecore User Profile Data Using Sitecore PowerShell Extensions

  • Twitter
  • LinkedIn

Updating Sitecore User Profile Data Using Sitecore PowerShell Extensions

Migrating Sitecore Experience Platform user profile data can be a headache, but it should not be. In this article, we will explore a great way of migrating user profile data that is a time saver and easily implementable. A simple and no headache way of migrating user profile data.

The Problem

We had a project where users were being migrated from one SXP version to another. Aside from creating all existing users from on to the other, it was also important that any needed profile data must be moved as well. And lastly, any users on the new system that is not found on the old one must be disabled.

Note: Some images were taken from actual project files. Some names have been covered for privacy purposes.

A major assumption that we have for this is that all users have been migrated and generated on the new system. Each user has their username and password but not their profile data. This is where we come in.

The profile data is stored in a CSV file and it will be for us to find a match and update the profile accordingly.

Figure 1: Excerpt of our CSV source file for profile data

The Solution

It would be fool hardy to use .NET for this since it s a 1-time thing and it can be costly to develop and execute. Given the circumstances, our best bet is using PowerShell Sitecore PowerShell Extensions (SPE).

Here is a link to docs and everything on SPE.

https://doc.sitecorepowershell.com/

The good news is that most if not all modern Sitecore Experience Platform (9+) have the extension installed. This makes our implementation easier and is an assumption that we will take.

Figure 2: PowerShell Extension App

Here is a list of things our final script should be able to do:

  1. Read all SC users from a domain (e.g. extranet)
  2. Read all users in the CSV file
  3. Match SC users to CSV users
  4. Disable Users not in CSV
  5. Update profile info for matched users. Note that most properties are not yet mapped. Sample provided
  6. Enable Matched users
  7. Do not process extranet/Anonymous account

The Script

Before we dive into the actual script, we will need some test accounts to see if we are doing the right thing. Below, we have 3 accounts and expect the following after we run our script.

  1. 0597 Existing in CSV and expects the account to be updated and kept enabled.
  2. Anonymous Expected to be skipped and not processed.
  3. NotInCSV Not in CSV and expects the account to be disabled.

Figure 3: Sample users (BEFORE)

Step 1 Get the existing user accounts for extranet domain:

Figure 4: Script to Get Existing Domain Users

Step 2 Load and Get the User Profile Data to Copy in the CSV file

Figure 5: Script to load CSV data

Step 3 Loop for each existing user, find a match if any and do required action

Figure 6: Script that loops and updates users as needed

Trying it out

In order to test this script, we will need to launch the PowerShell ISE app in the App Launcher as well as have the CSV file at the designated place in the script. Once app opens, we can then copy and paste our code to it text editor and click Execute.

Figure 7: Script in action

Our script ran and is showing its own before and after of the User Accounts. No errors generated on the output means everything went well. Our screenshot below shows our updates for 0597 account and for NotInCSV account as well.

Figure 8: Sample users (AFTER)

Summary

Sitecore PowerShell Extensions (SPE) made doing these updates so much easier than having to code up some backend code and deploying it. Not only did SPE made it easier, it also made it convenient to do and of course, faster.

Addendum:

Some have told me to provide me to provide the PowerShell script file so here it is.

https://github.com/JohnMontes/SXP_UpdateUserProfiles_PowerShellScript

Related Blogs

Latest Blogs