当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 无法识别术语“Connect-SPOService”

作者:精品下载站 日期:2024-12-14 20:56:57 浏览:14 分类:玩电脑

无法识别术语“Connect-SPOService”


[玩转系统] 无法识别术语“Connect-SPOService”

最近,一位开发人员联系了我们,他遇到了以下问题:

Connect-SPOService : The term 'Connect-SPOService' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At line:1 char:1
+ Connect-SPOService
+ ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Connect-SPOService:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

最大的挑战是 Sharepoint PowerShell 模块肯定安装在他的系统上。以下输出证实了这一点:

PS C:\WINDOWS\system32> Get-Module -ListAvailable *sharepoint*


    Directory: C:\Program Files\WindowsPowerShell\Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Binary     16.0.21... Microsoft.Online.SharePoint.Powe...
Script     0.1.0      SharePointOnline.CSOM               {Load-SPOnlineCSOMAssembly, Load-SPOnlineCSOMAssemblies}
Binary     3.29.21... SharePointPnPPowerShellOnline       {Add-PnPAlert, Add-PnPApp, Add-PnPApplicationCustomizer, Add-PnPClientSidePage...}

(如果您没有安装 Microsoft.Online.SharePoint.PowerShell 模块,请在此处获取)

如您所见,安装了多个 SharePoint 模块。但为什么 Connect-SPOService 不起作用?

注意到上面的输出中有一些非常奇怪的东西吗?模块 Microsoft.Online.SharePoint.PowerShell 没有任何导出的命令!

不同的文件版本

这一事实促使我调查系统上可用的 .dll 版本的一致性。

使用以下简洁的 PowerShell 简短语句来列出文件版本。该路径假定您已安装具有管理员权限的 SharePoint PowerShell 模块:

Get-ChildItem -Path 'C:\Program Files\WindowsPowerShell\Modules\Microsoft.Online.SharePoint.PowerShell\*Microsoft.SharePoint*.dll' -Recurse | ft Name,@{Label="Version";Expression={$_.VersionInfo.FileVersion}} -AutoSize

这应该生成类似于以下内容的输出:

Name                                       Version
----                                       -------
Microsoft.SharePoint.Client.dll            16.0.21213.12000
Microsoft.SharePoint.Client.Publishing.dll 16.0.21213.12000
Microsoft.SharePoint.Client.Runtime.dll    16.0.21213.12000

然后在您的系统中搜索不匹配的 .dll。就我而言,我在全局程序集缓存中找到了它们:

Get-ChildItem -Path C:\Windows\Microsoft.NET\assembly\GAC_MSIL\*Microsoft.SharePoint*.dll -Recurse | ft Name,@{Label="Version";Expression={$_.VersionInfo.FileVersion}} -AutoSize

您会注意到我们的两个 PowerShell dll 运行良好,但第三个 (Microsoft.SharePoint.Client.Publishing.dll) 在我的系统上有不同的版本:

  1. PowerShell 模块的(较新)版本为 16.0.21213.12000
  2. 全局程序集缓存的(较旧的)版本为 16.0.6518.1200

为了测试这是否确实是罪魁祸首,我从全局程序集缓存中删除了 Microsoft.SharePoint.Client.Publishing.dll,并尝试再次列出我的 SharePoint PowerShell 模块:

PS C:\WINDOWS\system32> Get-Module -ListAvailable *sharepoint*


    Directory: C:\Program Files\WindowsPowerShell\Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Binary     16.0.21... Microsoft.Online.SharePoint.Powe... {Register-SPODataEncryptionPolicy, Update-SPODataEncryptionPolicy, Get-SPODataEncryptionPolicy, Get-SPOSiteDataEncryptionPolicy...}
Script     0.1.0      SharePointOnline.CSOM               {Load-SPOnlineCSOMAssembly, Load-SPOnlineCSOMAssemblies}
Binary     3.29.21... SharePointPnPPowerShellOnline       {Add-PnPAlert, Add-PnPApp, Add-PnPApplicationCustomizer, Add-PnPClientSidePage...}

答对了!如您所见,现在可以在 Microsoft.Online.SharePoint.PowerShell 模块中找到命令。这绝对是一个好兆头?

正如预期的那样,我现在能够成功连接到 SharePoint Online:

PS C:\WINDOWS\system32> Connect-SPOService

cmdlet Connect-SPOService at command pipeline position 1
Supply values for the following parameters:
Url:

概括

我希望本文能够帮助您使用 PowerShell 模块连接到 SharePoint Online。

如果您喜欢尽可能简单高效地进行 Office 365 管理,请花几分钟时间查看 Easy365Manager。

Easy365Manager 是 Active Directory 用户和计算机管理控制台的经济实惠的 Office 365 扩展。借助 Easy365Manager,您可以在一个工具中管理本地用户和组、Office 365 许可证和邮箱。超级简单!

立即停止在多个 Web 控制台之间切换。下载并安装功能齐全的 30 天试用版。大多数管理员永远不会回头......

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯