signin and password does not match

Aase Nomad 246 Reputation points

I'm trying to connect to SharePoint Online but I'm getting this error and not 100% sure why so I would be really appreciated if I can get any help or suggestion why it might be.

I believe it might have to do with my tenant using MFA so just wondering how can I connect/login using MFA?.

   $SiteURL = ""  
   $ServerRelativeUrl= "documents/Testing"  
   Try {  
       #Get Credentials to connect  
       $Cred= Get-Credential  
       #Setup the context  
       $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)  
       $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)  
       #Get the web from URL  
       $Web = $Ctx.web  
       #Get the Folder object by Server Relative URL  
       $Folder = $Web.GetFolderByServerRelativeUrl($ServerRelativeUrl)  
       #Call the function to empty Folder  
       Empty-SPOFolder $Folder  
       #Delete the given Folder itself  
       Write-host  -f Green "Deleting Folder:"$Folder.ServerRelativeUrl  
       $Folder.Recycle() | Out-Null  
   Catch {  
       write-host -f Red "Error:" $_.Exception.Message  


Azure Active Directory
Azure Active Directory
An Azure enterprise identity service that provides single sign-on and multi-factor authentication.
13,681 questions
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
6,520 questions
SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,385 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.
4,766 questions
No comments
{count} votes

Accepted answer
  1. Yi Lu_MSFT 17,171 Reputation points

    Hi @Aase Nomad
    You could using the following cmd to connect to SharePoint Online with MFA:

    #Add required references to OfficeDevPnP.Core and SharePoint client assembly  
    [System.Reflection.Assembly]::LoadFrom("C:\Program Files\WindowsPowerShell\Modules\SharePointPnPPowerShellOnline\3.29.2101.0\OfficeDevPnP.Core.dll")   
    $siteURL = ""  
    $AuthenticationManager = new-object OfficeDevPnP.Core.AuthenticationManager  
    $ctx = $AuthenticationManager.GetWebLoginClientContext($siteURL)  
    Write-Host "Title: " $ctx.Web.Title -ForegroundColor Green  
    Write-Host "Description: " $ctx.Web.Description -ForegroundColor Green  

    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.

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. sadomovalex 3,601 Reputation points

    with MFA you have to use interactive (or web login). In addition to CSOM you may use PnP.PowerShell which contain large set of ready cmdlets for various tasks related with SPO. Interactive login with PnP.PowerShell will look like that:

    Connect-PnPOnline -Url $url -Interactive  
    2 people found this answer helpful.
    No comments