Update SharePoint Online userprofile properties – Powershell

The below powershell script is to update a user profile property called ‘CostCenter’ and you can replace with your property and update it.

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”

$SiteUrl = “https://tenant-admin.sharepoint.com”

$password = Read-Host -Prompt “Enter password” -AsSecureString

$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials(“jollsam@tenant.com”, $password)

#Set up the context

$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)

$Context.Credentials = $credentials

$targetAccount = “i:0#.f|membership|jollsam@tenant.com”

$PropertyName= “CostCenter”

$Value = “17029”

$peopleManager = New-Object Microsoft.SharePoint.Client.UserProfiles.PeopleManager($Context)

Write-Host “Updating User Profile Property `”$PropertyName`” for account – `”$targetAccount`”” -ForegroundColor Green

$peopleManager.SetSingleValueProfileProperty($targetAccount, $PropertyName, $Value)

$Context.ExecuteQuery()

Advertisements

About jollsam

10 years of experience in SharePoint Development, Administration and Solution/Infrastructure Architecture.
This entry was posted in sharepoint. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s