如何从本地文件夹安装/更新 powershell 模块 - 设置内部模块存储库 [英] How to install/update a powershell module from a local folder - set up an internal module repository

查看:29
本文介绍了如何从本地文件夹安装/更新 powershell 模块 - 设置内部模块存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在一个生产机器上安装一个 PowerShell 模块(即 sqlserver),但是,生产服务器没有任何互联网连接.

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

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

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.

使用 save-module 然后复制 &paste 看起来很不可靠,因为我不知道 install-module 是否真的会做一些 DLL 文件注册或安装.

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.

任何 PS 专家都可以提供一些想法如何做到这一点,即在没有互联网连接的情况下使用安装模块吗?

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

提前感谢您的时间.

PS:我知道有一个帖子,但确实如此帮不了我.

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'

您文件夹中的所有 .nupkg 文件现在都可以被 Install-Module 发现.

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

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

In an elevated shell (Run as Administrator):

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

这篇关于如何从本地文件夹安装/更新 powershell 模块 - 设置内部模块存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆