Unable to login using PowerShell (Connect-SPOService -Url <url-admin> -Cred) SharePoint Online

Ashish Javiya 1 Reputation point
2021-12-14T14:25:02.407+00:00

Hello,

Quick suggestion would be helpful.

I have 2 MFA enabled on sharepoint online. Looking to pass the credentials to avoid manual touch in script.

I have noticed that when we use the command it gives the new MS prompt to login

Connect-SPOService

while adding Connect-SPOService -Credential it go backed to Old prompt of MS - which result into error

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

$username = "******@XX.onmicrosoft.com"
$password = "XXXX"
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $userName, $(convertto-securestring $Password -asplaintext -force)
Connect-SPOService -Url https://XXXX-admin.sharepoint.com -Crednetial $cred -Region Default

defiantly - tried all the solution available including proxy and all - go success.

Microsoft 365 and Office SharePoint For business Windows
{count} votes

1 answer

Sort by: Most helpful
  1. Elsie Lu_MSFT 9,801 Reputation points
    2021-12-15T06:46:31.74+00:00

    Hi @Ashish Javiya ,

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

    According to this error message, there are two possible reasons for this error – either you have made a mistake while inserting your credentials, or you have a multi-factor authentication enabled (MFA). If it is due to the MFA, you will need to remove the -Credential parameter while connecting to SharePoint Online and enter your credentials with the traditional, login page experience.

    ===================================================

    And please refer to this blog for more information about how to connect SPO with MFA
    Connect to SharePoint Online using PowerShell with MFA (Multi-factor Authentication)

    Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.


    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.