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

Panos Konstantinidis 1 Reputation point
2022-06-24T08:56:59.607+00:00

Hello, I am trying to connect to SharePoint via Connect-PnPOnline. When I add my credentials for the SharePoint url in Windows Credential Manager and I type

Connect-PnPOnline -Url https://<domain>.sharepoint.com

everything works fine. However when I try the same with the following script

$username="<username>"
$encpassword = convertto-securestring -String "<password>" -AsPlainText -Force
$url = "https://<domain>.sharepoint.com/"
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $encpassword
Connect-PnPOnline -Url $url -Credentials $cred

It fails with the error message "Connect-PnPOnline : The sign-in name or password does not match one in the Microsoft account system."

Any idea why it's doing it? I am trying to write a script that connects to SharePoint and reads a file, without user interaction.

Thank you

SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,767 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,435 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Limitless Technology 39,471 Reputation points
    2022-06-27T07:24:01.147+00:00

    Hi there,

    Here are the possible causes and solutions for your issue.

    -Your password may be expired, or your account may be locked out or disabled.
    -Your saved password in the Windows credentials store could be incorrect or expired (especially when you use PnP PowerShell module Connect-PnPOnline to get credentials from the Windows Credentials store)
    -Instead of using the User name and password, you can use App ID & Password: How to Connect to SharePoint Online using AppID and AppSecret in PnP PowerShell?
    -Last but not least: You may have a conditional access policy setup in your environment. Exclude your user account from it.

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

    https://learn.microsoft.com/en-us/answers/questions/805576/connect-sposervice-the-sign-in-name-or-password-do.html

    -------------------------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept it as an answer–

    2 people found this answer helpful.

  2. Tong Zhang_MSFT 9,141 Reputation points
    2022-06-27T03:05:57.6+00:00

    Hi @Panos Konstantinidis ,

    Please try to do a troubleshooting:

    1. Please ensure that the username and password are correct.
    2. Please check if the account with multi-factor authentication (MFA).

    If your account with multi-factor authentication (MFA), your script will not work. You can use the following methods to connect to SharePoint Online:

    1.Method 1:

    Connect-SPOService -Url https://YourTenant-admin.sharepoint.com  
    

    2.Method 2:

    #Site Variables  
    $SiteURL = "https://crescent.sharepoint.com"  
    
    #Connect to PnP Online  
    Connect-PnPOnline -Url $SiteURL -UseWebLogin  
    

    3.Method 3:

    #Site collection URL  
    $SiteURL = "https://crescent.sharepoint.com"  
    
    #Connect to SharePoint Online with AppId and AppSecret  
    Connect-PnPOnline -Url $SiteURL -ClientId "xxxxxxxx" -ClientSecret "xxxxxxxx"  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    1 person found this answer helpful.