In this SharePoint online error we will discuss how to resolve the error: Connect-SPOService : The remote server returned an error: (401) Unauthorized. The remote server returned an error (401) Unauthorized SharePoint online management shell error.
Recently while working with SharePoint online management shell we got the below error which says:
Connect-SPOService : The remote server returned an error: (401) Unauthorized.
At line:2 char:1
+ Connect-SPOService -Url http://onlysharepoint2013-admin.sharepoint.com/ -credent …
+ CategoryInfo : NotSpecified: (:) [Connect-SPOService], WebException
+ FullyQualifiedErrorId : System.Net.WebException,Microsoft.Online.SharePoint.PowerShell.ConnectSPOService
Get-SPOSite : No connection available. Use Connect-SPOService before running this CmdLet.
At line:3 char:1
+ CategoryInfo : NotSpecified: (:) [Get-SPOSite], InvalidOperationException
+ FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.Online.SharePoint.PowerShell.GetSite
We were connecting to SharePoint online site using SharePoint online management shell.
Below was the command we were trying.
Import-Module Microsoft.Online.SharePoint.Powershell -Verbose Connect-SPOService -Url http://onlysharepoint2013-admin.sharepoint.com/ -credential [email protected] Get-SPOSite
The remote server returned an error (401) unauthorized
We were giving the -admin site also in the Url parameter, but still, the issue was coming.
We found out that the URL was creating the issue. we were providing http://onlysharepoint2013-admin.sharepoint.com/ (with http not with https)
We need to provide the URL as https URL. Office 365 URLs are always https.
So we replace the URL like https://onlysharepoint2013-admin.sharepoint.com/
You may like the following PowerShell SharePoint tutorials:
- PowerShell read all files from folder and subfolder
- How to upload files to SharePoint using PowerShell
- PowerShell SharePoint site collection example
- How to Change SharePoint Site Logo + PowerShell
- Display warning message in SharePoint site using PowerShell
- How to get file modification time and date using PowerShell
- Get sharepoint site template PowerShell
This resolved the issue. We did not receive any The remote server returned an error: (401) Unauthorized error.
Bhawana Rathore is a Microsoft MVP (3 times in Office Apps & Services) and a passionate SharePoint Consultant, having around 10 years of IT experience in the industry, as well as in .Net technologies. She likes to share her technical expertise in EnjoySharePoint.com and SPGuides.com