Forum Discussion

IT Support's avatar
IT Support
Copper Contributor
Sep 20, 2018

Bulk update custom user profile properties for SharePoint Online

I would like to update the SharePoint user profiles to display the mobile number.

 

I found it can be done with PowerShell and a JSON file (https://docs.microsoft.com/en-us/sharepoint/dev/solution-guidance/bulk-user-profile-update-api-for-sharepoint-online)

 

I am trying to get the JSON file properly but I am not if the properties name are correct:

 

Here is an example:

 

{  
   "value":[  
      {  
         "UserName":"jdoe@acme.com",
         "CellPhone":"+35 6 5326 7922"
      }

]

}

 

Can anybody please confirm I should UserName and CellPhone

 

UserName is the UPN

  • IT Support's avatar
    IT Support
    Copper Contributor

    And here is the script:

    # Get needed information from the end user
    $adminUrl = Read-Host -Prompt 'Enter the admin URL of your tenant'
    $userName = Read-Host -Prompt 'Enter your user name'
    $pwd = Read-Host -Prompt 'Enter your password' -AsSecureString
    $importFileUrl = Read-Host -Prompt 'Enter the URL to the file located in your tenant'

    # Get instances to the Office 365 tenant using CSOM
    $uri = New-Object System.Uri -ArgumentList $adminUrl
    $context = New-Object Microsoft.SharePoint.Client.ClientContext($uri)

    $context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName, $pwd)
    $o365 = New-Object Microsoft.Online.SharePoint.TenantManagement.Office365Tenant($context)
    $context.Load($o365)

    # Type of user identifier ["Email", "CloudId", "PrincipalName"] in the user profile service
    $userIdType=[Microsoft.Online.SharePoint.TenantManagement.ImportProfilePropertiesUserIdType]::PrincipalName

    # Name of user identifier property in the JSON
    $userLookupKey="UserName"

    # Create property mapping between the source file property name and the Office 365 property name
    # Notice that we have here 2 custom properties in UPA called 'City' and 'OfficeCode'
    $propertyMap = New-Object -type 'System.Collections.Generic.Dictionary[String,String]'
    $propertyMap.Add("CellPhone", "CellPhone")


    # Call to queue UPA property import
    $workItemId = $o365.QueueImportProfileProperties($userIdType, $userLookupKey, $propertyMap, $importFileUrl);

    # Execute the CSOM command for queuing the import job
    $context.ExecuteQuery();

    # Output the unique identifier of the job
    Write-Host "Import job created with the following identifier:" $workItemId.Value

    • IT Support's avatar
      IT Support
      Copper Contributor

      I tried to run the script and get:

       

      Exception calling "ExecuteQuery" with "0" argument(s): "Property name [CellPhone] can be edited by the user."
      At line:35 char:1
      + $context.ExecuteQuery();
      + ~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
          + FullyQualifiedErrorId : ServerException
       
      Import job created with the following identifier: 00000000-0000-0000-0000-000000000000

      • Jeroen Derde's avatar
        Jeroen Derde
        Copper Contributor

        A bit late, but might save someone a little time later on.

        See:  https://docs.microsoft.com/en-us/sharepoint/dev/solution-guidance/bulk-user-profile-update-api-for-sharepoint-online

         

        Property Names [AboutMe] are editable by user.This would be thrown by the CSOM API when you call the ExecuteQuery method when submitting the job to your tenant. The API validates that all properties currently being mapped are NOT user editable. The exception points out the property that cannot be used.

        In this example, we have tried to map a JSON property to the AboutMe property in the user profile service properties, but this is not allowed because AboutMe is a user editable property.

Resources