0

I am trying to connect to SharePoint with the below PowerShell code. And for my account Multi-Factor Authentication is enabled.

$AdminSiteURL= "https://xxxxxxxxx"
Connect-PnPOnline -Url $AdminSiteURL -UseWebLogin

After running the code, web login window is prompting but its auto closing soon after 2 seconds. Unable to figure put the error.

Please help me with this issue.

1
  • Get-PnPList : Cannot contact site at the specified URL xxxxxxxxxx. At C:\Users\xxxxx\Documents\Admin1.ps1:4 char:1 + Get-PnPList + ~~~~~~~~~~~ + CategoryInfo : WriteError: (:) [Get-PnPList], ClientRequestException + FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Lists.GetList – Chimata Srilakshmi Oct 12 '20 at 11:16
1

Have you tried the below? It worked for me (multi-factor authentication)

Connect-PnPOnline -Url https://contoso.sharepoint.com -SPOManagementShell

More info at MS site

5
  • ...Thanks alot for the help. Connect-PnPOnline : A parameter cannot be found that matches parameter name 'SPOManagementShell'. getting above error after running above line. Please help me with the issue – Chimata Srilakshmi Oct 12 '20 at 11:18
  • You need to install SPO ManagementShell found at: microsoft.com/en-us/download/details.aspx?id=35588 – Matiur Rahman Oct 12 '20 at 12:21
  • I have already installed SPO Management shell but I the PnP powershell is not detecting -SPOManagementShell. Please help me if have to install anything else. – Chimata Srilakshmi Oct 13 '20 at 5:52
  • No, I've not installed anything else. If your "SharePoint Online Management" was installed correctly, you should be able to get to it from Windows run command. Are you able to do that? – Matiur Rahman Oct 13 '20 at 12:07
  • I guess, you Import-Module -Name SharePointPnPPowerShellOnline -Verbose imported the module first, right? – Matiur Rahman Oct 13 '20 at 12:25
0

A few things to check:

  1. Do you see any error message after the login window automatically close? If not, try executing a PnP command (e.g. Get-PnPList) and see if it returns any result or error.

    If you have previous signed in before executing the command, it might skip the authentication and log you in directly.

  2. Login to the site using browser and make sure the multi-factor authentication is functioning for your account.

  3. Clear the browser cache and then run the command again.

3
  • Thank you very much for the suggestion. I tried runnig the code by making the changes you mentioned. But I am getting the below error. Get-PnPList : Cannot contact site at the specified URL xxxxxxxxxx. At C:\Users\xxxxx\Documents\Admin1.ps1:4 char:1 + Get-PnPList + ~~~~~~~~~~~ + CategoryInfo : WriteError: (:) [Get-PnPList], ClientRequestException + FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Lists.GetList. Please help me in solving the error – Chimata Srilakshmi Oct 12 '20 at 11:20
  • I am able to get the list of titles available in the site. Hope I connected to the sharepoint site Title Id Url ----- -- --- Announcements 0fa5ac45-ce41-46fc-ae81-8cb3a45c4d29 /Lists/Announcements appdata dc3d4ede-9484-4038-91cf-dd73c66c83eb /_catalogs/appdata please suggest me if I am going wrong. Thankyou – Chimata Srilakshmi Oct 12 '20 at 12:16
  • @ChimataSrilakshmi What permission do you have in this site? Do you have trouble login into the site in web browser? Also what if you change it to another site URL? – Chelsea_MSFT Oct 13 '20 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.