Are you getting the error: connect-sposervice : the remote server returned an error: (403) forbidden in PowerShell SharePoint? I will show you here how to fix this issue.
I recently worked on a SharePoint project where I encountered an issue while working with the 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
Here, we tried retrieving the web title using PowerShell with CSOM (using client dlls to connect to SharePoint Online sites).
Below is the code we were writing to retrieve the 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 ran 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 another system that was working fine, but still the same error.
The solution to the error is to install the SharePoint Online client component SDK.
Download the SharePoint Online client component SDK and install it. Then restart PowerShell, and you can refer to it directly from the URL below.
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 it on the E drive in my local system.
After you install the SharePoint Online SDK, it will create a structure like the one below and 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 is to install it from NuGet packages.
Conclusion
In this tutorial, I have explained the solution for fixing an error like the one below.
- connect-sposervice : the remote server returned an error: (403) forbidden.
- exception calling “executequery” with “0” argument(s): “the remote server returned an error: (403) forbidden.”
- connect-pnponline : the remote server returned an error: (403) forbidden.
- the remote server returned an error (403) forbidden powershell
You may also like the following tutorials:
- Delete all items from a SharePoint Online list using PnP PowerShell
- The term ‘get-spweb’ is not recognized as the name of a cmdlet function PowerShell SharePoint error
- Install PnP PowerShell for SharePoint Online
- Create and Delete SharePoint Document Library Using PowerShell
- Exception calling ExecuteQuery with 0 argument(s): Unable to connect to the remote server error in PowerShell SharePoint Online

Hey! I’m Bijay Kumar, founder of SPGuides.com and a Microsoft Business Applications MVP (Power Automate, Power Apps). I launched this site in 2020 because I truly enjoy working with SharePoint, Power Platform, and SharePoint Framework (SPFx), and wanted to share that passion through step-by-step tutorials, guides, and training videos. My mission is to help you learn these technologies so you can utilize SharePoint, enhance productivity, and potentially build business solutions along the way.