Error: Exception calling “ExecuteQuery” with “0” argument[s]: “The remote server returned an error: [403] Forbidden.” in PowerShell scripts for SharePoint Online. Follow this checklist to resolve Executequery 403 forbidden error in SharePoint Online PowerShell: #Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#parameters
$SiteURL = "//Crescent.sharepoint.com"
$UserName = "[email protected]"
$Password = "Password goes here"
$SecurePassword= $Password | ConvertTo-SecureString -AsPlainText -Force
#Setup the Context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext[$SiteURL]
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials[$UserName, $SecurePassword]
$Ctx.Credentials = $Cred
#Get the Site Collection storage used
$Site = $Ctx.Site
$Ctx.Load[$Site]
$Site.Retrieve["Usage"]
$ctx.ExecuteQuery[]
$StorageUsed = [Math]::Round[[$Site.Usage.Storage/1MB],2]
#Get Site Collection Size
Write-host "Storage Used: $StorageUsed MB"
$TenantAdminURL = "//crescent-admin.sharepoint.com/sites/london"
#Connect to the Site
Connect-PnPOnline -URL $TenantAdminURL -Interactive
Get-PnPSite
Salaudeen Rajack
Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!
I am getting the following error when trying to upload files to the Azure blob storage. This was working fine before. Does anyone know why it would return a 403 Forbidden message? I am using C# in ASP.NET MVC and have installed the client library for Windows Azure Storage.
[WebException: The remote server returned an error: [403] Forbidden.] System.Net.HttpWebRequest.GetResponse[] +1322 Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext] +1144
[StorageException: The remote server returned an error: [403] Forbidden.] Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[RESTCommand1 cmd, IRetryPolicy policy, OperationContext operationContext] +4529 Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.UploadFromStreamHelper[Stream source, Nullable1 length, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext] +1303 Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.UploadFromStream[Stream source, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext] +29 Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.UploadFromFile[String path, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext] +84
asked Aug 3, 2017 at 18:51
Prithvi RamanaPrithvi Ramana
2011 gold badge4 silver badges12 bronze badges
3
According to the 403 exception, it seems that you have no access to the container.
This was working fine before
If you are using Azure storage account key to access the resource, please have a try to make sure that account key is not changed or you could regenerate it and try it again.
If you are using Service SAS, please have a try to make sure that it is not out of date. You also could use Azure portal or Microsoft Azure Storage Explorer to regenerate SAS token and try it again.
Update:
According to the comment:
Azure storage also support CORS, more detail please refer to document. We also could set CORS from azure portal, please refer to the screenshot.
answered Aug 4, 2017 at 1:20
Tom Sun - MSFTTom Sun - MSFT
23.4k3 gold badges26 silver badges43 bronze badges
7