I am using following commands to connect to my SharePoint Online environment.
- Connect-SPOService -Url "https://testdomain.sharepoint.com/sites/test1"
- Connect-PnPOnline -Url "https://testdomain.sharepoint.com/sites/test1"
In an ideal case this command should connect me to the site collection. I have verified that I am using correct UserName and Password.
But instead I am getting following errors
For command 1:
Connect-SPOService : Could not authenticate to SharePoint Online https://testdomain.sharepoint.com/sites/test1 using OAuth 2.0 At line:1 char:1 + Connect-SPOService -Url "https://testdomain.sharepoint.com/sites/test1" + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Connect-SPOService], AuthenticationException + FullyQualifiedErrorId : Microsoft.Online.SharePoint.PowerShell.AuthenticationException,Microsoft.Online.SharePoint.PowerShell.ConnectSPOService
For command 2:
Connect-PnPOnline : The remote server returned an error: (403) Forbidden. At line:1 char:1 + Connect-PnPOnline -Url "https://testdomain.sharepoint.com/sites/test1 ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Connect-PnPOnline], WebException + FullyQualifiedErrorId : System.Net.WebException,SharePointPnP.PowerShell.Commands.Base.ConnectOnline
Unusual behavior: When I am running below command.
Connect-PnPOnline -Url https://testdomain.sharepoint.com/sites/test1
-PnPO365ManagementShell -LaunchBrowser
i.e. with parameters "PnPO365ManagementShell" "LaunchBrowser", it works perfectly fine. I am not sure what's wrong.
Similar behavior
Also I have installed the nuget package for SharePointPnPCoreOnline v3.1.1809
in my Provisioning solution. So when I am running my provisioning code I get same error while establishing connection.
Last thing: When I use same commands from other VMs or colleagues machine with same Creds, it works perfectly fine. Means something is wrong on my machine.
Remove-PnPStoredCredential -Name https://tenant.sharepoint.com -Force
and then try to connect again ? Looks like those creds got stored , this command might helpConnect-SPOService -Url "https://testdomain-admin.sharepoint.com/
because SPO commandlets only work with admin site urls