PowerShell Install Module命令未失败但未安装模块

时间:2020-09-11 10:51:14

标签: powershell sharepoint-online powershellget

我正在尝试将SharePoint的PnP联机命令安装到我的PowerShell上,但是以下命令似乎不起作用;

Install-Module -name SharePointPnPPowerShellOnline -scope CurrentUser

该命令似乎运行正常,没有出现错误,但是当我尝试运行应已安装的命令时,出现错误消息,提示找不到该命令。

connect-pnponline : The term 'connect-pnponline' 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-pnponline
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (connect-pnponline:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

我查看了所有模块文件夹,但该模块不在其中任何一个中。我已经将我的环境路径与拥有这项工作的同事进行了比较,他们是相同的。

有人知道这是什么原因吗?

2 个答案:

答案 0 :(得分:1)

该模块可能未导入。您应该能够执行
Import-Module SharePointPnPPowerShellOnline,该操作应该导入您的模块,或者如果由于某种原因而无法导入它,则会给您一个错误。

要解决非自动加载问题,请检查以下内容:

答案 1 :(得分:0)

这是由于模块存储在OneDrive中引起的。默认情况下,我的模块路径设置为“%USERPROFILE%\ Documents \ WindowsPowerShell \ Modules”,但是由于安装了OneDrive,因此我的路径更改为“%USERPROFILE%\ OneDrive \ Documents \ WindowsPowerShell \ Modules”。

要解决此问题,我去了Documents> Windows Powershell> Modules并复制了链接。然后,通过“开始”菜单,转到“编辑系统环境变量”>“高级”>“环境变量”,突出显示PSModulePath,然后单击“编辑”。 在此窗口中,我单击“新建”并粘贴上面找到的链接。 这解决了我遇到的问题。