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 Bhawana@OnlySharePoint2013.onmicrosoft.com
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.
The remote server returned an error (401) Unauthorized
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 following PowerShell SharePoint tutorials:
- PowerShell SharePoint Commands
- 25+ PowerShell SharePoint Examples
- 3 Different ways to Change Site Collection URL in SharePoint 2013/2016 using PowerShell
This resolved the issue. We did not receive any The remote server returned an error: (401) Unauthorized error.
SharePoint Online FREE Training
JOIN a FREE SharePoint Video Course (3 Part Video Series)