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

Copper Contributor



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


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@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.

1 Reply
Hi Ashish,

As i know, you can't automate a connection to SPOService with MFA using "-credential" parameter.
You will have to remove MFA if you want to automate your script with this parameter.
I would suggest you create a service account without MFA, deactivate it, and activate it only when you need to run your script.
Or, look on PnP side if you can. PnP support App authentication which can achieve your goal.