Recently, I was trying to insert items to the SharePoint online list through the PowerShell command. The error came in the below line while calling the ExecuteQuery() method. The error comes as an Exception calling “ExecuteQuery” with “0” argument(s): “Unable to connect to the remote server”
$Context.ExecuteQuery().
Exception calling “ExecuteQuery” with “0” argument(s): “Unable to connect to the remote server”
You can write in Windows PowerShell ISE, or you can also use Visual Studio Code to write and debug PowerShell Script.

Exception calling ExecuteQuery with 0 argument(s): Unable to connect to the remote server
I was writing the code below to connect to the SharePoint Online site from PowerShell.
$SiteURL = "https://onlysharepoint2013.sharepoint.com/sites/Bhawana/"
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$securePassword=ConvertTo-SecureString "MyPassword" -AsPlainText -Force
$Context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials("bijay@XXXXX.onmicrosoft.com", $securePassword)
The username and password everything was working fine. The same code was also working on another server.
Then we saw the internet was not working on the server. We tried to open the site in a browser, but it did not open either. Once the internet was up, the code worked as expected.
Check out Create and Delete SharePoint Document Library Using PowerShell
ExecuteQuery” With “0” Argument(S): “The Remote Server Returned An Error: (403) Forbidden
You might also get an error like ExecuteQuery” With “0” Argument(S): “The Remote Server Returned An Error: (403) Forbidden while working with PowerShell SharePoint Online Office 365.
You can solve by adding Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll explicitly in the PowerShell script.
Import-Module “E:\Bijay\Microsoft.SharePoint.Client.dll”
Import-Module “E:\Bijay\Microsoft.SharePoint.Client.Runtime.dll”
Sometimes, even if you install the SharePoint Online management shell, you might get the above issue.
Exception calling “executequery” with “0” argument(s): the remote server returned an error: (403) forbidden
If you are still Exception calling “executequery” with “0” argument(s): the remote server returned an error: (403) forbidden error, you can try the below things.
- Open PowerShell ISE in administrator mode
- The user account should be an admin account.
I hope this will help to resolve the error “Exception calling ExecuteQuery with 0 argument(s): Unable to connect to the remote server error in PowerShell SharePoint.”
You may also like the following PowerShell tutorials:
- How to connect to Microsoft Teams using PowerShell
- SharePoint List Items CRUD Operations Using PnP PowerShell
- the term ‘connect-msolservice’ is not recognized as the name of a cmdlet function
- The term ‘get-spweb’ is not recognized as the name of a cmdlet function PowerShell SharePoint error

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.