0

I am trying to connect to a SharePoint online communication site which have MFA enabled, I tried running this command:

PS C:\WINDOWS\system32>  connect-pnponline "https://***.sharepoint.com/sites/***/"  -PnPO365ManagementShell -launchbrowser

where i will get a popup >> then i will enter the code >> enter username and password >> close the popup >> but I got this error:

WARNING: To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code D****9
to authenticate.
WARNING: Code has been copied to clipboard
connect-pnponline : Object reference not set to an instance of an object.
At line:1 char:2

Although I entered the above code and enter the username and password and confirm the MFA.

Anyone advice please?

0

Try using this:

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

OR

Connect-PnPOnline -Url https://contoso.sharepoint.com -PnPManagementShell -LaunchBrowser

-UseWebLogin

If you want to connect to SharePoint with browser based login. This is required when you have multi-factor authentication (MFA) enabled.

Source: Connect-PnPOnline

8
  • there is no command named "-PnPManagementShell" – John John Jan 19 at 16:15
  • There is..it is given in documentation link (in my answer). However, to login with MFA enabled I have used -UseWebLogin before and it works. try using it and let me know if it works. – Ganesh Sanap Jan 19 at 16:19
  • you mean -PnPO365ManagementShell not -PnPManagementShell – John John Jan 19 at 16:21
  • if i use -UseWebLogin i will be login automatically,, but if i try to perform any action will get access denied ... – John John Jan 19 at 16:22
  • I mean -PnPManagementShell (See Example 12 given in above link). Also PnPO365ManagementShell is Alias of -PnPManagementShell. – Ganesh Sanap Jan 19 at 16:35
0

As @Ganesh Sanap suggested, you may need to -UseWebLogin to sign in the MFA enabled account. And there is a new parameter -ForceAuthentication in the latest version of PnP PowerShell:

If this parameter is specified it will clear the cookies and you can log in with different credentials. This should prevent from auto-login.

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.