question

SyuheiMashino-1425 avatar image
0 Votes"
SyuheiMashino-1425 asked SyuheiMashino-1425 commented

The remote server returned an error: (403) Forbidden.

When I run this script, I get the following error:
Do you know the cause?

<-- Script -->

 $AdminAccount = '*****@tenant.onmicrosoft.com'
 $AdminPass = '*****'

 $secPass = ConvertTo-SecureString $AdminPass -AsPlainText -Force
 $Credential = New-Object System.Management.Automation.PSCredential($AdminAccount, $secPass)

 #SharePointSite
 $Site = "https://tenant.sharepoint.com/sites/WORK"

 #Connect SharePointSite
 Connect-PnPOnline -Url $Site -Credentials $credential

<-- Error -->

The remote server returned an error: (403) Forbidden.

office-sharepoint-onlinewindows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MichaelHan-MSFT avatar image
0 Votes"
MichaelHan-MSFT answered SyuheiMashino-1425 commented

Hi @SyuheiMashino-1425,

Please make sure you have enough permissions to access this site. You could try to access this site through browser, check if it is work.

Although you may use SharePoint admin or Global admin account, you still need to add yourself as the site admins to access this site: https://docs.microsoft.com/en-us/sharepoint/manage-site-collection-administrators



If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @SyuheiMashino-1425,
How are things going? Is there any update on your issue?
I am willing to hear from you.

0 Votes 0 ·

Thank you for your help!!

0 Votes 0 ·
cooldadtx avatar image
0 Votes"
cooldadtx answered

You do not have permission to connect to the given site. 403 means access denied. Check your credentials and verify they have permission to connect to the given SP site with the permissions you're asking for.

Note that the preference is to use an application ID instead of an admin ID. Refer to this article.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.