powershell: [BUG] Set-PnPUserProfileProperty : Access denied. You do not have permission to perform

Please see also related discussion Can Get nut can’t Set with pnp.powershell

Expected behavior

Cmdlet Set-PnPUserProfileProperty allows to update of user-profile properties

Actual behavior

Error is raised:

Set-PnPUserProfileProperty : Access denied. You do not have permission to perform this action or access this resource.
At line:1 char:1
+ Set-PnPUserProfileProperty -Account 'test@foobar.com ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Set-PnPUserProfileProperty], ServerUnauthorizedAccessException
    + FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.UserProfiles.SetUserProfileProperty

Steps to reproduce behavior

  1. Connect SharePoint Online
  2. Run following code: Set-PnPUserProfileProperty -Account 'test@foobar.com' -PropertyName 'WorkPhone' -Value '0123456789'

What is the version of the Cmdlet module you are running?

Manifest 1.3.0 PnP.PowerShell {Add-PnPAlert, Add-PnPApp, Add-PnPApplicationCustomizer, Add-PnPContentType...}

Which operating system/environment are you running PnP PowerShell on?

  • Windows
  • Linux
  • MacOS
  • Azure Cloud Shell
  • Azure Functions
  • Other : please specify

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 114 (9 by maintainers)

Commits related to this issue

Most upvoted comments

2023 is here. hope the teams working on this will get us a solution soon.

Everyone - I checked with Engineering a few day ago, which confirmed they are currently working on a hotfix for this issue. The plan is to release it this calendar year, I don’t have a more specific date.

ONE SOLUTION

Finally found a way to authenticate to SharePoint online to write profile properties without an interactive/user logon, that works from Azure function app. Unfortunately it uses ACS which is retired now but explicitly still supported for SharePoint use. So it’s not my preferred approach, but as it actually works, it’s better than all other approaches so far.

The key is to follow this article Granting access using SharePoint App-Only, but to add the scope /sharepoint/social/tenant. Update the Permission Request XML as follows, and it will permit writing user profile properties.

<AppPermissionRequests AllowAppOnlyPolicy="true">
  <AppPermissionRequest Scope="http://sharepoint/content/tenant" Right="FullControl" />
  <AppPermissionRequest Scope="http://sharepoint/social/tenant" Right="FullControl" />
</AppPermissionRequests>

Still looking for a more “modern” approach that’s not just supported as a waiver from a retired approach. Many thanks to all!

Everyone - I’m working at Microsoft Support, and with @KoenZomers and Engineering on this issue. Microsoft Engineering has analyzed this issue and is currently working on a fix. It requires collaboration between multiple teams and there is no ETA for the moment. I will update this thread as updates occur

Thanks @Markarend for taking the time to detail out what I mentioned above to help others better understand the workaround. Still I believe that should be seen as a workaround. We’re currently trying to see if filing a hotfix request for this has any chance of succeeding.

Here’s a non-interactive method for connecting that does work to change user profile properties from a script running in an Azure runbook or function: Example 3 on this page. You must make one change. Follow this article Granting access using SharePoint App-Only, but add the scope /sharepoint/social/tenant. Update the Permission Request XML as follows, and it will permit writing user profile properties.

<AppPermissionRequests AllowAppOnlyPolicy="true">
  <AppPermissionRequest Scope="http://sharepoint/content/tenant" Right="FullControl" />
  <AppPermissionRequest Scope="http://sharepoint/social/tenant" Right="FullControl" />
</AppPermissionRequests>

This ACS method is retired now but explicitly still supported for SharePoint use

Unfortunately the SharePoint Online support engineers are not always 100% up to date about the limitations of their own products… 😦 In this case the issue lies with the fact that a requested permission through an Azure AD application grant is not being recognized by SharePoint online specifically when it comes to the UPS (User Profile Service Application). With -UseWebLogin we use a different type of authentication (cookiebased/legacy) where as with all the other authentication methods we use the currently by Microsoft promoted way of authentication : Azure AD OAuth. We switched over to Azure AD OAuth as the default as more and more API requests we need to make are located in the Microsoft Graph. And the MS Graph only supports Azure AD OAuth.

In order for the OAuth authentication flow to work one needs to grant permissions to an Azure AD App registration, either a multi-tenant one alike the PnP Management Shell, or your own registered one. Our tests show that while the correct permissions are in place, SPO is not allowing the user to perform the actions. We brought this up with the product manager in charge of those APIs back then but are still awaiting feedback.

@kodsu yes, I got confirmation from Engineering that they are actively working on this and they already completed a good part of the work, although it is not finished yet. They did not communicate a timeline when it will ship in production, but it will not be before CY 2023.

Thanks @AndersRask for sharing and @ttd-kevinclement for confirming. I will update our documentation with this great info.

I guess with that, we can also finally close this long running open issue. Thanks for providing all the feedback and thoughts here everyone.

Just wanted to mention that New-PnPUPABulkImportJob works fine with an app registration with Certificate and permissions assigned only in AAD with SharePoint “Sites.FullControl.All” and “User.ReadWrite.All” and no permissions assigned in SPO at /_layouts/15/appinv.aspx , tested it this week in 2 different tenants.

@heinrich-ulbricht I’m just the messenger who understands the frustration of people in this thread who are waiting for this fix for so long. I take the time to chase Engineering and provide whatever update I have, even if it is a poor one. I could have chosen to just remain silent

Everyone - I checked with Engineering a few day ago, which confirmed they are currently working on a hotfix for this issue. The plan is to release it this calendar year, I don’t have a more specific date.

Time is just about up on this. Can we expect this to be fixed anytime soon? I have been patiently waiting for almost 2 years.

Waiting patiently for the fix from Microsoft.

Turns out engineering already had a backlog item open to implement those permissions. The need to have this implemented is raised to engineering through a Critical Design Change Request (CDCR) now based on the discussion here with the aim of prioritizing the backlog item on upcoming sprints. They’re currently looking into the efforts it would take to implement this.

It would be awesome if Microsoft could fix this for Azure AD app-only contexts. This has been an issue for a while, and you lose a bit of transparency for your app registrations when you are building AD Apps, and subsequently have to register some permissions though appinv.aspx

I just tested and indeed it doesn’t work with a bearer token (which is what we use by default). It seems that that is not (more?) supported. We’ll investigate that. I noticed that if you use -UseWebLogin (which is cookie based auth) it does work.

I’ll leave this issue open while we investigate.

In my testing the issue with ACL is now solved, and so legacy auth using appreg.aspx is no longer needed. I have tested using both system managed identity and app reg with cert. Both works fine updating user profile properties including term set fields with only API permissions

Set-PnPUserProfileProperty -Account adelev@contoso.onmicrosoft.com -PropertyName "SPS-Location" -Value "Stockholm"

The key is adding TermStore.ReadWrite.All. You can ignore the exchange perm as it was only used for testing image

Anyone updates for the new year?

@Yvand Hello, have you got any news/ETA ? For anyone having issue with non interactive login please refer to @Markarend comments which have a workaround while waiting for the Microsoft fix, especially this one https://github.com/pnp/powershell/issues/277#issuecomment-866839692

@WiljanD I got no update since my last message but I just asked for one, I’ll post back here if/when I get an answer

Still patiently waiting on Microsoft to fix this (not the community).

Quick update on my end. I am able to get the “workaround” solution to work (creating Azure App Registration then using AppInv.aspx to use the legacy ACS authorization with permission scopes outlined above), but only if I Connect-PnPOnline using ClientId and ClientSecret parameters: ConnectPnPOnline -Url "myco-admin.sharepoint.com" -ClientId "ZZZZZZ" -ClientSecret "abcdefghijklmnop" Note: Connect-PnPOnline gives me the warning about using legacy authentication when connecting this way. Yes, I am aware of -WarningAction Ignore.

Thank you! That works for me. What also works is -UseWebLogin on Connect-PnPOnline but that’s not as flexible.

Still not working with ConnectPnPOnline -Url “myco-admin.sharepoint.com” -ClientId “ZZZZZZ” -Tenant “myco.onmicrosoft.com” -Thumbprint “XXXXXXX”

When will MSFT fix this ?

Set-PnPUserProfileProperty : This operation requires you to be managing your own data or have administrator privileges. At line:12 char:5

  • Set-PnPUserProfileProperty -Account xxxxxx -Prope ...
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : WriteError: (😃 [Set-PnPUserProfileProperty], ServerException
    • FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.UserProfiles.SetUserProfileProperty

I know this one has been open for quite some time already and that there are a lot of organizations that are hitting this issue. I can say that we’re closer than ever on getting this addressed. I’m not at liberty to give any timelines on it, but know that we are still actively working on it internally to get it resolved. Thank you for your patience everyone.

@veronicageek depends a bit on how they decide to fix it. Most probably it will not need code changes from our end.

Morning @KoenZomers . You made my day, that was indeed the cause and solution. Thank you !

In addition, it is appreciated that you have discussed this case and looked at possible options.

As an update to this item. We have discussed the situation with engineering. They are aware of this situation and this GitHub thread and are evaluating their options.

I’d like to add that this is something I’d like to see resolved for a current client. While I can (barely) keep up with the subtle nuance and intricacies of things like this, clients/customers often times aren’t paying as close attention. As a result those that have to build/deliver/transition solutions that require both Azure App Registration and the legacy ACS permissions have a hard time explaining this to customer teams. It also requires delivery of code that will be known to have a limited life span in that ACS will only likely be supported for some (unknown) period of time. I’d like to vote this up in priority / escalation such that administrators can have custom SPO user profile sync jobs that don’t require ACS any longer that don’t require interaction from a user (i.e. for credentials).

@KoenZomers Thanks for updating me. The easy workaround you are talking about is app-only credential?

The easy workaround is to apply what is written here: https://github.com/pnp/powershell/issues/277#issuecomment-866839692

So you can combine your AAD App Registration with ACS permissions to make this work. You would just need to get another token from ACS to handle the user profile stuff, if you directly communicate with the SharePoint/Graph APIs. If you use PnP PowerShell, this will be done automatically for you and you just need to set the permissions as mentioned in the referenced post.

Just as an update, the topic is still on the table and has not been forgotten. No decision has been made yet if this functionality will be adjusted or not unfortunately.

@mohandivraniya that explains it then. WebLogin will work as it works through a cookie to authenticate. The issue I believe we are all facing here is that we cannot register an application in AAD, apply the SharePoint Application principal Users.ReadWrite.All and use that to update a user profile. You would either need to assign the same client Id social permissions through AppInv.aspx as well to make it work or alternatively use -UseWebLogin.

Thanks for sharing @apinales. Looking into it with the support team.

25392520

@wimp777 and as mentioned above the workaround for Azure AD registered application is to use Granting access using SharePoint App-Only, which works if you also add the scope /sharepoint/social/tenant to those instructions. I know it’s not the same as Azure AD registered but it’s close and it works.

I just tested and indeed it doesn’t work with a bearer token (which is what we use by default). It seems that that is not (more?) supported. We’ll investigate that. I noticed that if you use -UseWebLogin (which is cookie based auth) it does work.

I’ll leave this issue open while we investigate.

I tested it with -WebLogin and it indeed worked, thank you for that workaround. My environment is Windows, PnP.PowerShell 1.5.0.

Hi Bernard, the PnP projects are “community driven” and AFAIK don’t have a current timeline for fixing this. However please note there are many ways to connect with SharePoint online using PnP under different circumstances, and many of them do work. See the 13 different examples. May take some digging to get the most promising example for your scenario working. I needed to use Example 3 because of non-interactive login. First attempts didn’t work just, but then I found more details about dependencies and finally got it working:

The key is to follow this article Granting access using SharePoint App-Only, but to add the scope /sharepoint/social/tenant. Update the Permission Request XML as follows, and it will permit writing user profile properties.

<AppPermissionRequests AllowAppOnlyPolicy="true">
  <AppPermissionRequest Scope="http://sharepoint/content/tenant" Right="FullControl" />
  <AppPermissionRequest Scope="http://sharepoint/social/tenant" Right="FullControl" />
</AppPermissionRequests>

This ACS which is retired now but explicitly still supported for SharePoint use

To give you an update: this is not an issue with PnP PowerShell but has to do with how SharePoint Online handles authorization. We provided Microsoft with this feedback and are waiting for them to reply on it. We have no ETA when that will happen.

@veronicageek, my apologies for seeming demanding, the exclamation point is a bit overused these days! I absolutely appreciate everyone’s supporting each other, and I’ll post something if I find an answer. I’m trying some things in this article now: https://dev.to/svarukala/introducing-the-new-pnp-powershell-based-on-net-core-3-1-and-learn-how-it-s-authentication-works-pn7.

@Markarend

My customer needs a fix for this!

I’d like to remind you that this repo is community driven, from people contributing on their own personal time. So please be patient as we may also have unforeseen priorities.

@SebasT87 what version of SharePointPnP are you using as a workaround?

That would be SharePointPnPPowerShellOnline to be exact. Which can be installed using: Install-Module SharePointPnPPowerShellOnline