微软PowerShell无法安装模块,提示:Install-Module : 在模块“PowerShellGet”中找到“Install-Module”命令,但无法加载该模块。有关详细信息,请运行“Import-Module PowerShellGet”。
当运行Import-Module PowerShellGet
后:显示:
Import-Module : 无法加载文件 C:\Users\xxx\Documents\WindowsPowerShell\Modules\PackageManagement\1.4.7\PackageManagement.psm1,因为在此系统上禁止运行脚本
。有关详细信息,请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。
所在位置 行:1 字符: 1
+ Import-Module PowerShellGet
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [Import-Module],PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess,Microsoft.PowerShell.Commands.ImportModuleCommand
原因:
在计算机上启动 Windows PowerShell 时,执行策略很可能是 Restricted(默认设置)。
powershell 输入:get-executionpolicy
显示为: Restricted
解决方法:
修改执行策略:
输入: set-executionpolicy remotesigned