signin and password does not match

Aase Nomad 246 Reputation points
2022-02-13T22:46:52.337+00:00

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

   #Variables  
   $SiteURL = "https://companyName-my.sharepoint.com/personal/yzqpsn_nam_corp_m_com"  
   $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  
       $Ctx.Load($Web)  
       $Ctx.executeQuery()  
      
       #Get the Folder object by Server Relative URL  
       $Folder = $Web.GetFolderByServerRelativeUrl($ServerRelativeUrl)  
       $Ctx.Load($Folder)  
       $Ctx.ExecuteQuery()  
      
       #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  
       $Ctx.ExecuteQuery()  
   }  
   Catch {  
       write-host -f Red "Error:" $_.Exception.Message  
   }  

173869-image.png

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,567 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,604 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,508 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
21,371 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yi Lu_MSFT 17,481 Reputation points
    2022-02-14T06:47:56.84+00:00

    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")   
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")  
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")  
       
    $siteURL = "https://contoso.sharepoint.com/sites/siten_name"  
        
    $AuthenticationManager = new-object OfficeDevPnP.Core.AuthenticationManager  
    $ctx = $AuthenticationManager.GetWebLoginClientContext($siteURL)  
    $ctx.Load($ctx.Web)  
    $ctx.ExecuteQuery()  
        
    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,631 Reputation points
    2022-02-14T14:56:39.51+00:00

    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.
    0 comments No comments

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.