I am trying to update the user profile properties (CellPhone for example) using the below code in SharePoint online by power-shell.
Mysite URL
$site = 'site url'
Admin User Principal Name
$admin = 'user login'
Get Password as secure String
$password = "Password" |ConvertTo-SecureString -AsPlainText -force
Get the Client Context and Bind the Site Collection
$context = New-Object Microsoft.SharePoint.Client.ClientContext($site)
Authenticate
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($admin , $password)
$context.Credentials = $credentials
Fetch the users in Site Collection
$users = $context.Web.SiteUsers
$context.Load($users)
$context.ExecuteQuery()
Create an Object [People Manager] to retrieve profile information
$people = New-Object Microsoft.SharePoint.Client.UserProfiles.PeopleManager($context)
$userprofile = $people.GetPropertiesFor("useraccount")
$context.Load($userprofile)
$context.ExecuteQuery()
$people.SetSingleValueProfileProperty($userprofile.AccountName, "CellPhone", "1234567890")
$context.ExecuteQuery()
I've created a trial O365 SharePoint site and I'm the admin of the site.
I'm able to update my phone no. using the above code but getting access denied for any other user.
I've tried to update the properties of an external user(Hotmail) that I've added in my site also I tried with a test user account that I created with the same domain of my site. I'm getting access denied for both.
Any suggestions?