When I try to connect to a SharePoint Online via Powershell (using the script below) I always receive the error...

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

This would make sense if MFA was enabled. It is not. I am also able to connect to other SharePoint Online sites fine.

Powershell Script

$URL = "https://mysite.sharepoint.com"
$login = "[email protected]"
$pwd = "secure-password"

$pwd = ConvertTo-SecureString $pwd -AsPlainText -Force;
$credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $login, $pwd

Connect-PnPOnline -Url $url -Credentials $credentials
  • Seems the issue is happening in specific site, can you login into the site with same username/password in browser ?
    – Jerry
    Dec 16, 2020 at 1:04
  • @Jerry_MSFT yes. Dec 16, 2020 at 20:32

1 Answer 1


Likely due to Modern Auth.


Connect-PnPOnline -Url https://tenantName.sharepoint.com/sites/siteName -UseWebLogin
  • "UseWebLogin" will work but how do you can not store credentials with that flag. Dec 16, 2020 at 2:29
  • 1
    You shouldn't store credentials. Use the Graph API with Client ID + Certificate, instead. docs.microsoft.com/en-us/azure/active-directory/develop/… You can then use Connect-PnPOnline -Url -ClientId <value> -Certificate (or -CertificatePath, etc.).
    – user6024
    Dec 16, 2020 at 16:54
  • That is just for an example. Once it's working then I can use credential manager. Regardless it doesn't work as intended. Dec 16, 2020 at 20:34
  • 1
    Not sure what you mean by doesn't work as the CID/Secret|Certificate certainly does work. Cred Manager, if I recall, will not work since you need to content with Modern Auth + MFA.
    – user6024
    Dec 17, 2020 at 18:41

Your Answer

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

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