安装PowerShellGet模块

时间:2017-09-14 18:57:04

标签: powershell

我正在使用Windows 2012 R2,它运行的是PowerShell 4.0版。我已升级到5.0版。

似乎当我执行基本命令时会出现错误,例如,

PS C:\Windows\system32> Install-Module –Name PowerShellGet –Force –Verbose
  

Install-Module:在模块中找到了“Install-Module”命令   'PowerShellGet',但无法加载模块。更多   信息,运行'Import-Module PowerShellGet'。在行:1个字符:1   + Install-Module -Name PowerShellGet -Force -Verbose   + ~~~~~~~~~~~~~~       + CategoryInfo:ObjectNotFound:(Install-Module:String)[],CommandNotFoundException       + FullyQualifiedErrorId:CouldNotAutoloadMatchingModule

另一个例子:

PS C:\Windows\system32> import-module PowerShellGet
  

获取变量:术语“获取变量”未被识别为名称   cmdlet,函数,脚本文件或可操作程序。检查   拼写名称,或者如果包含路径,请验证路径   是正确的,然后再试一次。在C:\ Program   文件\ WindowsPowerShell \模块\ PowerShellGet \ 1.1.3.2 \ PSModule.psm1:18   焦炭:28   + $ script:IsWindows =( - not(Get-Variable -Name IsWindows -ErrorAction ...   + ~~~~~~~~~~~~       + CategoryInfo:ObjectNotFound:(Get-Variable:String)[],CommandNotFoundException       + FullyQualifiedErrorId:CommandNotFoundException

我基本上遵循PowerShellGet的安装方法:https://docs.microsoft.com/en-us/powershell/gallery/psget/get_psget_module

我被困在本指南的“安装模块”命令中。

2 个答案:

答案 0 :(得分:1)

如果您已升级到WMF 5.0,则可以使用PowerShellGet。运行:

Set-PSRepository -Name PSGallery -InstallationPolicy Trusted

然后,您可以使用Find-Module和Install-Module来获取所需内容。

答案 1 :(得分:0)

在执行安装模块之前,先在Powershell上执行以下命令:“ Set-ExecutionPolicy Unrestricted”。 (受限模式可帮助您防范未经授权的脚本)

相关问题