SharePoint Shell error: The sign-in name or password does not match one in the Microsoft account system.

王 暁凡 Xiaofan Wang 5 Reputation points
2023-03-16T06:40:54.47+00:00

When I use the following Shell to get SharePoint's data:

(This is not the complete code)

    # 処理対象サイトコレクションのURLをファイル出力
    Write-Host "Site:[${siteUrl}]"

    # SharePoint Online に接続
    $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)

    # 認証
    $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password) 
    $ctx.Credentials = $credentials  

Then the following error displayed, and I cannot continue to work:

"0" 個の引数を指定して "ExecuteQuery" を呼び出し中に例外が発生しました: "The sign-in name or password does not match on
e in the Microsoft account system."
発生場所 C:\RMS\temp\Report-IrmStatusCheckAll.ps1:61 文字:5
+     $ctx.ExecuteQuery()
+     ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : IdcrlException

"0" 個の引数を指定して "ExecuteQuery" を呼び出し中に例外が発生しました: "The sign-in name or password does not match on
e in the Microsoft account system."
発生場所 C:\RMS\temp\Report-IrmStatusCheckAll.ps1:23 文字:5
+     $ctx.ExecuteQuery()
+     ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : IdcrlException

The collection has not been initialized. It has not been requested or the request has not been executed. It may need to
 be explicitly requested.
発生場所 C:\RMS\temp\Report-IrmStatusCheckAll.ps1:24 文字:13
+     foreach($checkWeb in $checkWebs){
+             ~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], CollectionNotInitializedException
    + FullyQualifiedErrorId : Microsoft.SharePoint.Client.CollectionNotInitializedException

"0" 個の引数を指定して "ExecuteQuery" を呼び出し中に例外が発生しました: "The sign-in name or password does not match on
e in the Microsoft account system."
発生場所 C:\RMS\temp\Report-IrmStatusCheckAll.ps1:69 文字:9
+         $ctx.ExecuteQuery()
+         ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : IdcrlException

"0" 個の引数を指定して "ExecuteQuery" を呼び出し中に例外が発生しました: "The sign-in name or password does not match on
e in the Microsoft account system."
発生場所 C:\RMS\temp\Report-IrmStatusCheckAll.ps1:72 文字:9
+         $ctx.ExecuteQuery()
+         ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : IdcrlException

The collection has not been initialized. It has not been requested or the request has not been executed. It may need to
 be explicitly requested.
発生場所 C:\RMS\temp\Report-IrmStatusCheckAll.ps1:75 文字:17
+         foreach($list in $lists){
+                 ~~~~~
    + CategoryInfo          : OperationStopped: (:) [], CollectionNotInitializedException
    + FullyQualifiedErrorId : Microsoft.SharePoint.Client.CollectionNotInitializedException

Please tell me how to solve it.

Thank you.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,693 questions
0 comments No comments
{count} vote

3 answers

Sort by: Most helpful
  1. Xyza Xue_MSFT 24,716 Reputation points Microsoft Vendor
    2023-03-16T08:45:49.7833333+00:00

    Hi @王 暁凡 Xiaofan Wang ,

    Our forum is an English forum, it is recommended to post in English to avoid misunderstandings. According to machine translation, your question is that "The sign-in name or password does not match on e in the Microsoft account system." error occurs when using MFA to connect to SharePoint Online.

    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.

    1 person found this answer helpful.

  2. 王 暁凡 Xiaofan Wang 5 Reputation points
    2023-03-20T03:51:01.9366667+00:00

    Hi @Xyza Xue_MSFT ,

    Thanks for your reply.

    I'm sorry that I don't know how to change the shell language into English, so I have to attach the test result in Japanese.

    I would appreciate it if you could use translation machine to translate the error message and confirm why this error displayed.

    And it is still cannot work normally at present, please check the error below.

    Could you please tell me how to fix it?

    Thank you so much.

    new-object : 型 [OfficeDevPnP.Core.AuthenticationManager] が見つかりません。この型を含むアセンブリが読み込まれているこ
    とを確認してください。
    発生場所 C:\RMS\temp\Report-IrmStatusCheckAll.ps1:58 文字:30

    • ... nticationManager = new-object OfficeDevPnP.Core.AuthenticationManager
      +                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : InvalidType: (:) [New-Object], PSArgumentException
          + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand   null 値の式ではメソッドを呼び出せません。
      発生場所 C:\RMS\temp\Report-IrmStatusCheckAll.ps1:61 文字:5
      +     $ctx = $AuthenticationManager.GetWebLoginClientContext($siteURL)
      +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : InvalidOperation: (:) []、RuntimeException
          + FullyQualifiedErrorId : InvokeMethodOnNull   null 値の式ではメソッドを呼び出せません。
      発生場所 C:\RMS\temp\Report-IrmStatusCheckAll.ps1:62 文字:5
      +     $ctx.Load($ctx.Web)
      +     ~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : InvalidOperation: (:) []、RuntimeException
          + FullyQualifiedErrorId : InvokeMethodOnNull   null 値の式ではメソッドを呼び出せません。
      発生場所 C:\RMS\temp\Report-IrmStatusCheckAll.ps1:63 文字:5
      +     $ctx.ExecuteQuery()

    0 comments No comments

  3. Xyza Xue_MSFT 24,716 Reputation points Microsoft Vendor
    2023-03-20T08:47:12.18+00:00

    Hi @王 暁凡 Xiaofan Wang ,

    Try to use following cmd to connect to SharePoint Online with MFA:

    #Add required references to SharePoint client assembly
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
     
    $userAccount = "alexw@contoso.com"
    $password = "password"
    $siteURL = "https://contoso.sharepoint.com/sites/site_name"
     
    $secPwd = $(ConvertTo-SecureString $password -asplaintext -force) 
    $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl) 
    $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userAccount,$secPwd) 
    $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.


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.