如何将PowerShell脚本分发给团队成员?

问题描述 投票:0回答:1

我与一群软件开发人员合作,我有一堆方便的PowerShell脚本来自动构建/部署等...我希望我所有的同事能够安装和使用这些脚本。如果他们在我添加更多功能/修复错误时获得自动更新,那就太好了。

这些是私有脚本,不想像https://www.powershellgallery.com/那样发布

今天,我们团队中的每个开发人员都从git repo下载这些脚本,并将此文件夹添加到$path。此文件夹有一个.bat文件,用于打开powershell控制台。在此控制台中,他们可以获得帮助并调用各种可用命令。今天他们需要调用一个从repo中获取最新信息的命令。

我觉得应该有比这更好的东西,我正在为powershell脚本寻找类似dotnet global tools的东西。

powershell dotnet-tool
1个回答
0
投票

至于......

这些是私有脚本,不希望发布到位

..然后建立自己的预备回购。

如何执行此操作由Microsoft和其他人完整记录,如下所示:

Setting up an Internal PowerShellGet Repository

Powershell: Your first internal PSScript repository

# Network share
# The other thing we should have is an empty folder on a network share. This will be the location of our repository. Your users will need to have access to this location if they are going to be loading content from it.


$Path = '\\Server\Share\MyRepository'


# If you just want to experiment with these commands, you can use a local folder for your repository. PowerShellGet does not care where the folder lives.


# Creating the repository
# The first thing we should do is tell PowerShellGet that our $Path is a script repository.

Import-Module PowerShellGet

$repo = @{
    Name = 'MyRepository'
    SourceLocation = $Path
    PublishLocation = $Path
    InstallationPolicy = 'Trusted'
}

Register-PSRepository @repo


# And we are done.

Get-PSRepository

Name         InstallationPolicy SourceLocation
----         ------------------ --------------
MyRepository Trusted            \\Server\Share\MyRepository
PSGallery    Untrusted          https://www.powershellgallery.com/api/v2/


# Other than creating a folder, there is no complicated setup to creating this repository. Just by telling PowerShellGet that the folder is a repository, it will consider it to be one. The one catch is that you need to run this command on each machine to register the repository.

或者站起来自己的内部git服务器。

Bonobo Git Server for Windows是一个可以在IIS上安装的Web应用程序。它提供了一个简单的管理工具,并可以访问您自己托管在服务器上的git存储库。

https://bonobogitserver.com/features

https://bonobogitserver.com/install

OP的更新

至于你的后续行动:

一旦我将文件放在本地计算机中,如何将它带入当前的PowerShell会话?

请记住,Import-Module是关于本地计算机上已加载的模块,而不是来自任何本地或远程仓库的模块。您仍然必须安装模块表单,无论您目标是什么回购。

如果模块已正确定义并安装在本地计算机上,如果您使用的是PowerShell v3及更高版本,则不应使用Import-Module,因为正确设计和实现后,它们应自动加载。

具体来说,您的后续问题是此Q&A的副本如何从本地文件夹安装/更新PowerShell模块 - 设置内部模块存储库

您只需要执行正常步骤即可获取并使用您的仓库中的模块。

Find-Module -Name 'MyModule' -Repository MyRepository | 
Save-Module -Path "$env:USERPROFILE\Documents\WindowsPowerShell\Modules"

Install-Module -Name 'MyModule'

Import-Module -Name 'MyModule'

也可以看看:

Update-Module

© www.soinside.com 2019 - 2024. All rights reserved.