Connect-SPOService error:Could not load type 'Microsoft.SharePoint.Client.SharePointOnlineCredentials

Connect-SPOService error:Could not load type 'Microsoft.SharePoint.Client.SharePointOnlineCredentials

我正在尝试使用 Powershell Connect-SPOService 连接到 SharePoint 但我收到错误:

| Could not load type 'Microsoft.SharePoint.Client.SharePointOnlineCredentials' from assembly
     | 'Microsoft.SharePoint.Client.Runtime, Version=16.1.0.0, Culture=neutral,
     | PublicKeyToken=71e9bce111e9429c'.

我重新安装了 Microsoft.Online.SharePoint.PowerShell 并导入了它。但还是。 我也安装了 PnP.PowerShell。这会是问题所在吗?

这是由于 DLL 版本不匹配。要解决此问题,请执行以下步骤:

  1. 卸载 SharePoint Online 管理 Shell 和 SharePoint Online 客户端 SDK(如果已安装)。
  2. 从以下位置删除 SharePoint Online 客户端程序集:C:\Windows\Microsoft.NET\assembly\GAC_MSIL,删除名称开头的所有文件夹:Microsoft.SharePoint*
  3. 使用 Uninstall-Module -Name Microsoft.Online.SharePoint.PowerShell 卸载模块并重新安装模块 Install-Module -Name Microsoft.Online.SharePoint.PowerShell