I'm working with PnP PowerShell to upload files to a SharePoint library after setting up a new App registration. I can connect using a certificate without any issues, and the app has the permissions Sites.Manage.All and Sites.ReadWrite.All, which should allow it to interact with all SharePoint sites. While I can delete files and folders on two sites, I'm facing an 'Access Denied' error when trying to upload a file using Add-PnPFile on another site. What could be the issue? Is there a setting I need to adjust on the SharePoint side?
4 Answers
Have you checked the app permissions for both sites? You can verify them in the AppInv.aspx page by looking up your app ID. Make sure to add the following permission requests:
This approach can sometimes resolve access issues.
You might want to double-check if you're trying to upload the file to the 'Shared Documents' folder. Sometimes the specific library path matters when it comes to permissions.
As a follow-up, I realized that the exact library name matters. Instead of using "Documents", you might want to reference it as "Shared%20Documents" to avoid access issues.
PnP errors can be pretty vague. It sounds like this could be more about the document library settings rather than an issue with your script.
I found that I could upload files to a new document library without issues, but the default 'Documents' library was giving me the access denied message. No idea why, but just in case, when you reference the library in your script, use "Shared%20Documents" instead of just "Documents".