PSSnapin Microsoft.Sharepoint.Powershell 未安装在此计算机上

PSSnapin Microsoft.Sharepoint.Powershell is not installed on this computer

当我尝试 运行 SharePoint Online 管理中的命令 Add-PSSnapin Microsoft.SharePoint.Powershell Shell

我收到以下错误:

Add-PSSnapin : The Windows PowerShell snap-in 'Microsoft.SharePoint.Powershell` is not installed on this computer

+ CategoryInfo: InvalidArgument: (Microsoft.SharePoint.Powershell:string) [Add-PSSnapin], PSArgumentException

根据我的理解,这应该与 SharePoint Online Management Shell 一起安装(这是一个全新的下载)为什么它不让我安装它

我可以使用 $AdminURL、$AdminName 和 $Password 登录到 Sharepoint,所以这不是世界末日(并证明这应该有效),但显然使脚本变得不那么容易 运行跨站点,因为每次都必须修改它以更改 url 和管理员名称

编辑:我在另一个 post 上读到,添加这个模块(不是 snapin)可以解决我的错误 Get-SPSite is not recognized as the name of a cmdlet, function, script file, or operable programGet-SPWebApplication is not recognized as the name of a cmdlet, function, script file, or operable program 但是,这并没有解决我的问题...

如用户@kuzimoto 所述,我使用的命令与 SharePoint Online 不兼容,旨在与 SharePoint Server 结合使用。

正确的连接方式是使用命令 Connect-SPOService 并通过那里传递凭据,或者将它们硬编码到您的脚本中。