Forum Discussion
Bulk update custom user profile properties for SharePoint Online
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
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 DerdeJan 08, 2019Copper 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.