什么是Powershell中的Install-Module命令?


8

Microsoft的各种文章都引用了Powershell命令Install-Module,但是我找不到任何关于它实际上是什么的引用,并且谷歌搜索也不是很合适。我已经安装了psget,所以我有其版本的Install-Module ...,但我认为这不是其他所有人都在谈论的Install-Module。

啊,我找到了这个Install-Module。这与PsGet所安装的有所不同吗?如果是这样,我应该卸载PsGet以便恢复到默认状态吗?


“那是另外一个吗?” -不;在示例Install-Module中用于安装Azure Resource ManagerInstall-Module本身是PowerShell 3.0 Azure Resource Manager的一部分,也是PowerShell 5的一部分
Ramhound 2015年

感谢@Ramhound-我安装了psget,它添加了一个Install-Module命令,因此我认为这已覆盖了PS随附的Install-Module。
罗里2015年

我认为这并不能保证,但是如果模块本身被添加,这是一个安全的选择。
Ramhound 2015年

Answers:


18

我以前安装的PSGet覆盖了我的Install-Module。您可以通过运行检查它,help install-module并查看它指的是哪个版本。

我找不到PSGet的卸载文档,因此我通过删除文件夹将其删除C:\Users\Rory\Documents\WindowsPowerShell\Modules\PSGet。现在help install-module指的是Microsoft版本。


1
如果没有引用,则这是卸载任何模块的正确方法。默认情况下,PsGet没有任何内容,因此只需删除它就可以了。
Mike Chaliy

1
您可能需要重新启动Powershell命令窗口才能生效。
大卫·怀特

1
在我的计算机上,psget已安装在C:\ Program Files \ WindowsPowerShell \ Modules下
dinnouti

9

您可以通过在命令前面加上模块名称来解决冲突:

PsGet的安装和安装方式:

C:\repos> install-module csproj
Module csproj was not found in central repository
At C:\Users\Administrator\Documents\WindowsPowerShell\Modules\PsGet\PsGet.psm1:694 char:13
+             throw "Module $Module was not found in central repository ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Module csproj w...tral repository:String) [], RuntimeException
    + FullyQualifiedErrorId : Module csproj was not found in central repository

使用限定名称:

C:\repos> powershellget\install-module csproj

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running
the Set-PSRepository cmdlet. Are you sure you want to install the modules from 'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): y
C:\repos>

感谢http://windowsitpro.com/blog/dealing-cmdlet-name-conflicts

通过阅读文档的URL获得的模块名称-https: //msdn.microsoft.com/powershell/reference/5.1/PowerShellGet/install-module

更多信息:https : //andrwwatt.wordpress.com/2006/05/13/coping-with-a-powershell-naming-clash/

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.