How to install/update a powershell module from a local folder - set up an internal module repository

泄露秘密 提交于 2019-12-07 02:05:36

问题


I need to install a PowerShell module (i.e. sqlserver) on one production box, however, the production server does not have any internet connection.

An alternative way I am using is to use save-module to save module files onto a shared folder and then copy the files from the shared folder directly to production server's PS module path

c:\program files\WindowsPowerShell\Modules

It works, but I am just wondering whether we can use the existing approach, i.e. install-module, something like

install-module -name sqlserver -repository "my shared folder"

This requirement extends to update-module as well.

Using save-module and then copy & paste seems very unreliable because I have no idea whether install-module will actually do some DLL file registration or installation.

Can any PS gurus please give some idea how to do this, i.e. using install-module without internet connection?

Thanks in advance for your time.

PS: I know there is a post at SO but it does not help me.


回答1:


  1. In any shell (elevated or not):

    Register-PSRepository -Name 'myRepositoryName' -SourceLocation 'my folder'
    

    All .nupkg files inside your folder are now discoverable by Install-Module.

  2. In an elevated shell (Run as Administrator):

    Install-Module 'Some-Module' -Repository 'myRepositoryName'
    


来源:https://stackoverflow.com/questions/49987884/how-to-install-update-a-powershell-module-from-a-local-folder-set-up-an-intern

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!