如何从本地文件夹安装/更新Powershell模块-设置内部模块存储库

jya*_*yao 6 powershell powershellget

我需要在一个生产盒上安装PowerShell模块(即sqlserver),但是生产服务器没有任何Internet连接。

我使用的另一种方法是使用save-module将模块文件保存到共享文件夹中,然后将文件从共享文件夹直接复制到生产服务器的PS模块路径中

c:\program files\WindowsPowerShell\Modules
Run Code Online (Sandbox Code Playgroud)

它可以工作,但是我只是想知道我们是否可以使用现有的方法,即安装模块,例如

install-module -name sqlserver -repository "my shared folder"
Run Code Online (Sandbox Code Playgroud)

该要求也扩展到更新模块。

使用保存模块然后进行复制和粘贴似乎非常不可靠,因为我不知道安装模块是否实际上会进行某些DLL文件注册或安装。

任何PS专家都可以提出一些建议,例如在没有Internet连接的情况下使用安装模块吗?

在此先感谢您的时间。

PS:我知道在SO上有个职位,但这对我没有帮助。

Eri*_*sen 12

  1. 在任何外壳(升高或不升高)中:

     Register-PSRepository -Name 'myRepositoryName' -SourceLocation 'C:\MyExampleFolder'
    
    Run Code Online (Sandbox Code Playgroud)

    .nupkg文件夹中的所有文件现在都可以通过Install-Module.

  2. 在提升的 shell 中(以管理员身份运行):

     Install-Module 'Some-Module' -Repository 'myRepositoryName'
    
    Run Code Online (Sandbox Code Playgroud)

  • @Timo 不完全是。“Import-Module”使您可以在“当前 PowerShell 会话”中访问模块的 cmdlet。`Install-Module` *将模块的文件复制到某个位置*。进口就像把食物放在柜台上做三明治,而安装就像去购物并将食物从商店带回家。 (2认同)