Help! Getting a 401 Unauthorized Error with PnP Online

0
4
Asked By JazzHandz94 On

Hey everyone! I'm trying to set up a connection to SharePoint using the PnP PowerShell module, and I'm authenticating with a certificate. Despite following all the steps correctly, I'm hitting a 401 Unauthorized error. Here's the command I'm running:

```powershell
connect-pnponline -url $ConnectionURL -ClientId $ClientId -Tenant $TenantId -CertificatePath $CertPath -CertificatePassword (ConvertTo-SecureString $CertPassword -AsPlainText -Force) -Verbose
```

The verbose output shows that it's trying to connect using Entra ID App-Only with the certificate, but I can't seem to get past the Unauthorized status.

I've also assigned all the necessary permissions and granted admin consent for both Microsoft Graph and SharePoint. Everything looks correct, but I just can't figure out what's wrong. Any advice would be greatly appreciated!

2 Answers

Answered By CuriousCoder88 On

It sounds like you might need to double-check the SharePoint permissions. I faced a similar issue before. Make sure you run this command to grant the necessary site permissions:

```powershell
Grant-PnPAzureADAppSitePermission -AppId -DisplayName -Permissions -Site
```

You can find more info in the [documentation here](https://pnp.github.io/powershell/cmdlets/Grant-PnPAzureADAppSitePermission.html).

TechSavvyEmma -

I tried that, but even after granting full control to the app, I’m still hitting a 401 error.

DevInDisguise -

This is usually needed only if you're using Graph API permission for Sites.Selected, which doesn’t apply in your case.

Answered By ScriptSlinger101 On

Have you checked the output from `Get-PnPContext`? Sometimes it can give you clues about what's going wrong with the connection.

JazzHandz94 -

Not really, I’m not sure what to look for in the output, to be honest.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.