Hey everyone! I'm having a tough time trying to upload a file to SharePoint Online and it feels like I've been at it all day. Here's what I'm working with:
I'm trying to upload a file located at 'G:ReportsDecember_2025M365 Licences Data.xlsx' to the Reports library on my SPO site (https://xxxx.sharepoint.com/sites/Infra_Reports). I've set up my connection using the following code:
```
$SiteURL = "https://xxxxx.sharepoint.com/sites/Infra_Reports"
$ClientId = "4sfw343r255ecbdy44b"
$ClientSecret = "xxxxxxxxx"
$LocalPath = "G:ReportsDecember_2025M365 Licences Data.xlsx"
$LibraryPath = "Reports"
Connect-PnPOnline -Url $SiteURL -ClientId $ClientId -ClientSecret $ClientSecret
Add-PnPfile -Path $LocalPath -Folder $LibraryPath
```
But I'm getting this error: 'Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))' despite having the right permissions like SharePoint → Sites.FullControl.All and Sites.ReadWrite.All set. I've also tried uninstalling and reinstalling, yet nothing seems to help. Can anyone guide me on what else I could try?
2 Answers
It seems like the method you're using might not be supported anymore. If you're using a Client Secret, your best option would be to switch to the Microsoft Graph API. Check out this guide for uploading files with that: https://sposcripts.com/how-to-upload-files-to-sharepoint-using-graph-api/. Alternatively, if you want to stick with the PnP Module, consider using a Certificate instead, as that's still a viable option. You’ll just need to generate a self-signed certificate and upload it to your App Registration. That way, you can authenticate with SharePoint Online using the certificate thumbprint in the Connect-PnPOnline cmdlet.
I would recommend using the Graph API too. I moved away from PnP when we switched to a fully cloud setup. Unless there's a very specific need for PnP, I haven't found it necessary since. The Graph API gives you a lot of flexibility!

Related Questions
How To Get Your Domain Unblocked From Facebook
How To Find A String In a Directory of Files Using Linux