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

时间:2019-04-30 18:10:20

标签: powershell dotnet-tool

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

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

那样发布

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

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

1 个答案:

答案 0 :(得分: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是一个Web应用程序,您可以   在您的IIS上安装。它提供了一种简单的管理工具,并可访问   您自己托管在服务器上的git存储库。

     

https://bonobogitserver.com/features

     

https://bonobogitserver.com/install

OP更新

至于您的后续行动:

  

一旦我在其本地计算机中保存了文件,将如何带来它   进入他们当前的Powershell会话?

请记住,导入模块是关于要在本地计算机上加载的模块,而不是来自任何本地或远程存储库的模块。您仍然必须以目标存储库的形式安装模块。

如果正确定义了模块并将其安装在本地计算机上,并且在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