Introduction
In this article, you will learn how to update SharePoint user profile properties programmatically in different ways using CSOM with PowerShell on SharePoint online - Office 365 sites. The update property option is available only on Office 365 sites as of now and it is not available on on-premise versions.
Steps Involved
The following prerequisites need to be executed before going for any operations using CSOM PowerShell on SharePoint sites.
- Add the references using the Add-Type command with necessary reference paths. The necessary references are Microsoft.SharePoint.Client.dll, Microsoft.SharePoint.Client.Runtime.dll and UserProfile dll. The references should be from 16 folder, since these are latest updates from Microsoft.
- Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
- Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
- Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.UserProfiles.dll"
- Initialize client context object with the site URL.
- $siteURL = ""
- $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL)
- If you are trying to access SharePoint Online site, then you need to setup the site credentials with credentials parameter and get it set to the client context.
- #Setting Credentials for o365 - Start
- $userId = ""
- $pwd = Read-Host -Prompt "Enter password" -AsSecureString
- $creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userId, $pwd)
- $ctx.credentials = $creds
- #Setting Credentials for o365 - End
- There are multiple ways of updating the properties of SharePoint user profile. There will be properties with just a value or line of text and properties with collection of values. Two different methods are used to update those properties. Following tells us with examples.
- Single Value properties - WorkPhone, Mobile, FirstName, LastName, etc.
- Multi Valued properties - Ask Me About, Skills, Interests, etc.
- Initialize the people manager object with the context to get the user profile data.
- Using SetSingleValueProfileProperty method set the property for any target user.
- Load the object and execute query to get the data.
- # Update User Profile property (office 365)
- function SetSingleValueProperty(){
- try{
- $peopleManager = New-Object Microsoft.SharePoint.Client.UserProfiles.PeopleManager($ctx)
- $peopleManager.SetSingleValueProfileProperty("i:0#.f|membership|[email protected]", "AboutMe", "Your description")
- $ctx.Load($peopleManager)
- $ctx.ExecuteQuery()
- Write-Host "Property updated"
- }
- catch{
- Write-Host "$($_.Exception.Message)" -foregroundcolor Red
- }
- }

Yogendra BhardwajPosted Nov 16, 2016, 11:54 PM
I have found the root cause that i was running script in Windows Power Shell windows instead of sharepoint Management shell
Yogendra BhardwajPosted Nov 15, 2016, 10:32 PM
Yes , i have checked at location C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\ in fact i removed Sharepoint Online SDK and Install again but same result
Yogendra BhardwajPosted Nov 11, 2016, 11:27 PM
I have checked SDK version and using this script for sharepoint online
Yogendra BhardwajPosted Nov 11, 2016, 11:27 PM
Method invocation failed because [Microsoft.SharePoint.Client.UserProfiles.PeopleManager] does not contain a method named 'SetSingleValueProfileProperty'.
Yogendra BhardwajPosted Nov 11, 2016, 11:27 PM
HI There i am getting error below
Vignesh ManiPosted May 27, 2016, 4:27 PM
nice
Sonu ChaudharyPosted May 27, 2016, 10:15 AM
good one
Debasis SahaPosted May 26, 2016, 3:32 PM
Nice sharing..
Kuppurasu NagarajPosted May 26, 2016, 12:38 PM
Nice Sharing..