This PowerShell SharePoint tutorial, we will discuss how to solve The remote server returned an error: (403) Forbidden.
Recently, I was taking a SharePoint corporate training, then we got the issue while working with SharePoint Online site using PowerShell. The error says:
Exception calling “ExecuteQuery” with “0” argument(s): The remote server returned an error: (403) Forbidden.

The remote server returned an error: (403) Forbidden PowerShell SharePoint Online
Here, we were trying to retrieve the web title using PowerShell with CSOM (using client dlls to connect to SharePoint Online sites).
Below code, we were writing to retrieve web title using PowerShell SharePoint Online.
Add-Type -Path "c:\Bijay\Microsoft.SharePoint.Client.dll"
Add-Type -Path "c:\Bijay\Microsoft.SharePoint.Client.Runtime.dll"
$siteUrl = "https://<tenantname>.sharepoint.com/sites/TSInfoIntranet"
$username = "bijay@<tenantname>.onmicrosoft.com"
$password = Read-Host -Prompt "Enter password" -AsSecureString
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)
$ctx.Credentials = $credentials
$rootWeb = $ctx.Web
$ctx.Load($rootWeb)
$ctx.ExecuteQuery()
Write-Host $rootWeb.Title
But when I run the PowerShell script using Windows PowerShell ISE, it gave an error as Exception calling “ExecuteQuery” with “0” argument(s): The remote server returned an error: (403) Forbidden.
From the error, it looks like there was an error in the login details. I verified the Site URL, login name and password and everything was perfect.
Also, copy the SharePoint client dlls from one more system where it was working fine, but still the same error.
The solution to solve the error is to install SharePoint Online client component SDK.
Download SharePoint Online client component SDK and install it. Then restart the PowerShell and then you can refer it from the below URL directly.
Add-Type -Path "E:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "E:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Here I have installed in E drive in my local system.
After you install the SharePoint Online SDK, it will create a structure like below and it will also contain the required dlls.
E:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\
After this the error “Exception calling “ExecuteQuery” with “0” argument(s): The remote server returned an error: (403) Forbidden.” will not come.
The other way, we can also install it from NuGet packages.
You may like following SharePoint PowerShell tutorials:
- Retrieve all list names and list guids from SharePoint online site using PowerShell
- Working with PowerShell Variables
- SharePoint 2016 PowerShell Script to list all Users in Site Collection
- SharePoint 2013 backup and restore using PowerShell
- SharePoint Online storage limits (Detailed Guide)
- PowerShell find files modified in last N days
- Create a web application in SharePoint 2016 from Central Administration and using PowerShell
- Insert/Add item to SharePoint Online list using PowerShell
- Delete list items created before N days using PowerShell in SharePoint Online
- Get SharePoint document library size using PowerShell
- PnP PowerShell commands for SharePoint Online Site
This PowerShell SharePoint tutorial, we learned how to solve the error: Exception calling “ExecuteQuery” with “0” argument(s): The remote server returned an error: (403) Forbidden.
I am Bijay a Microsoft MVP (8 times –Â My MVP Profile) in SharePoint and have more than 15 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com