3

My Question:

Is it possible to easily update multiple user profiles, but NOT one at a time? I need to update a user profile property for every user - thousands of them.

Scenario:

We have a custom user property in SharePoint called "Unit" - similar to a team. It is a Single-Value String using metadata.

However, I've been asked to change it to "Units" and make it a Multi-Value String to accommodate a few users.

I was unable to convert Unit to Multi-Value so I created an new property called Units that is Multi-Value.

Now I have to copy and paste... one at a time... Unit to Units for every user. Thousands of them.

Thanks in advance!

6

You can execute the following PowerShell script. It instantiates the User Profile Manager and loops through each "Profile", copying Unit property value in Units property.

$url = "<mySiteUrl>"
$site = Get-SPSite $url
$context = Get-SPServiceContext $site
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
$profiles = $profileManager.GetEnumerator()

while ($profiles.MoveNext()) {
  $userProfile = $profiles.Current
  $name = $userProfile.DisplayName
  $unit = $userProfile["Unit"]
  $userProfile["Units"].Value = $unit;
  $userProfile.Commit();

}

The account running the PowerShell script needs “Full Control” permissions on the User Profile Service Application and on the AppFabic Caching Service. (I used the AppFabic Caching Service account, which has Full Control on the User Profile Service, to launch the script).

0

This is not a direct answer on your question, but just side note about SharePoint Online (office 365) and bulk user profile properties updates (also might be useful for potential googlers).

For SharePoint Online there is a special API allowing you to bulk update multiple profiles in one go with CSOM.

You need to:

  1. Create json file describing users and properties:
{
  "value": [
    {
      "IdName": "vesaj@contoso.com",
      "Property1": "Helsinki",
      "Property2": "Viper"
    },
    {
      "IdName": "bjansen@contoso.com",
      "Property1": "Brussels",
      "Property2": "Beetle"
    }
  ]
}
  1. Upload file to SharePoint.
  2. Call QueueImportProfileProperties:
// Create instance to Office 365 Tenant object. Technically not needed to load though. 
Office365Tenant tenant = new Office365Tenant(ctx);
ctx.Load(tenant);
ctx.ExecuteQuery();

// Type of user identifier ["PrincipleName", "EmailAddress", "CloudId"] in the 
// User Profile Service. In this case we use email as the identifier at the UPA storage
ImportProfilePropertiesUserIdType userIdType = 
      ImportProfilePropertiesUserIdType.Email;

// Name of user identifier property in the JSON file
var userLookupKey = "IdName";

var propertyMap = new System.Collections.Generic.Dictionary<string, string>();

// First one is the property at the JSON file, 
// second is the user profile property Name at User Profile Service
// Notice that we have here 2 custom properties in UPA called 'City' and 'OfficeCode'
propertyMap.Add("City", "City");
propertyMap.Add("Office", "OfficeCode");

// Returns a GUID, which can be used to see the status of the execution and end results
var workItemId = tenant.QueueImportProfileProperties(
      userIdType, userLookupKey, propertyMap, fileUrl
      );

ctx.ExecuteQuery();
  1. Check job status:
// Load all import jobs – old and queued ones
Office365Tenant tenant = new Office365Tenant(ctx);
var jobs = tenant.GetImportProfilePropertyJobs();
ctx.Load(jobs);
ctx.ExecuteQuery();
foreach (var item in jobs)
{
   // Check whatever properties needed
   var state = item.State;
}  

More info here - Introducing the API for bulk custom user profile properties update for SharePoint Online

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.