0

I have this script to connect to a SharePoint online site using username & password:

$encpassword = convertto-securestring -String "********" -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist "****@******.com", $encpassword

Connect-PnPOnline -Url https://******.sharepoint.com/ -Credentials $cred

But I am getting this error:

Connect-PnPOnline : AADSTS50076: Due to a configuration change made by your administrator, or because you moved to a
new location, you must use multi-factor authentication to access '00000003-0000-0ff1-ce00-000000000000'.
Trace ID: 0e616060-9737-4793-a2df-6dc7e1695000
Correlation ID: 6102bb1c-1b28-4979-994e-83ddb5ddf6e9
Timestamp: 2022-12-07 19:09:26Z
At line:1 char:1
+ Connect-PnPOnline -Url https://****.sharepoint.com/ -Credent ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Connect-PnPOnline], MsalUiRequiredException
    + FullyQualifiedErrorId : Microsoft.Identity.Client.MsalUiRequiredException,PnP.PowerShell.Commands.Base.ConnectOn
   line

Can anyone advice on this please?

2 Answers 2

1

Try using interactive authentication. This will allow you to complete the multi-factor authentication.

1

As MFA is enabled for user account, you have below two options while authenticating using Connect-PnPOnline:

  1. Use -Interactive (previously UseWebLogin):

    Connect-PnPOnline -Url https://******.sharepoint.com/ -Interactive
    
  2. Use App Password for Office 365:

    You can use App password in place of normal password to login easily.

    I am using App Password for authentication in PowerShell as well as SharePoint Designer and it works well.

    Create an app password for Office 365.

You can find more details in below threads:

  1. Connect-SPOService : The sign-in name or password does not match one in the Microsoft account system
  2. The sign-in name or password does not match one in the Microsoft account system

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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