CSOM return The sign-in name or password does not match one error

luee johnlu 80 Reputation points
2024-04-17T19:12:24.58+00:00

When connecting to sharepoint online site with csom. The code return the following error

"Exception calling "ExecuteQuery" with "0" argument(s): "The sign-in name or password does not match one in the Microsoft account system.".


And I am using following code

$ctx=New-Object Microsoft.Sharepoint.Client.ClientContext($siteCollUrl)
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName, $securePassword)
$web=$ctx.Web
$ctx.Load($web)
$ctx.ExecuteQuery()

The username and password was correct. Please help fix the issue.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,652 questions
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,673 questions
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 31,226 Reputation points Microsoft Vendor
    2024-04-18T01:57:01.76+00:00

    Hi @luee johnlu

    There are several reasons will cause the issue. Here are the possible causes and solutions:

    1. Your user name or password could be wrong (Obviously!). Check if you are able to log in using a web browser with the user name and password given in the PowerShell script.
    2. Your password may be expired, or your account may be locked out or disabled.
    3. 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)
    4. Your account may be MFA (Multi-factor authentication) enabled! If yes, either MFA must be turned OFF or you have to follow the methods described in How to Connect to SharePoint Online with MFA-enabled accounts from PowerShell?
    5. When you are working with multiple tenants, make sure the supplied credentials match the given URL. E.g. If you are trying to connect to https://crescent.sharepoint.com, make sure you are providing username@crescent.com (or whatever is appropriate!) but not “username@someotherdomain.com” in SharePoint Online.

    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.


0 additional answers

Sort by: Most helpful