0

I work with bunch of software developers, I have bunch of handy powershell scripts to automate building/deploying etc... I would like all my fellow co-workers to be able to install and use these scripts. It would be nice, if they get automatic updates as I add more features/fix bugs.

These are private scripts and don't want to publish in place like https://www.powershellgallery.com/

Today, every developer in our team downloads these scripts from a git repo and add this folder to $path. This folder has a .bat file that opens a powershell console. In this console they can get help and invoke various available commands. Today they need to invoke a command that pulls latest from repo.

I feel like there ought to be something better than this, I am looking for something like dotnet global tools for powershell scripts.

iraSenthil
  • 11,307
  • 6
  • 39
  • 49
  • If you have scripts that help with building/deploying, they should be in the same repository as the application. Beyond that, why not turn your scripts into NuGet packages and host them on an internal NuGet feed? People can register your NuGet feed and use standard `Install-Module` commands. – Daniel Mann Apr 30 '19 at 18:26
  • `git pull` pulls the latest data from the repo? Could make a powershell build script and attach it to run with each users profile which pulls from repo and imports each module you want available by default. Just be warned more modules you import the slower each startup would be. – Riley Carney Apr 30 '19 at 21:59
  • Thanks, Once I have the files in their local computer, how would the bring it into their current powershell session? – iraSenthil May 01 '19 at 13:29

1 Answers1

1

As for this...

These are private scripts and don't want to publish in place like

.. then build your own on prem repo.

How to do this is fully documented by Microsoft and other as seen here:

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.

Or stand up your own internal git server.

Bonobo Git Server for Windows is a web application you can install on your IIS. It provides an easy management tool and access to your git repositories that are self hosted on your server.

https://bonobogitserver.com/features

https://bonobogitserver.com/install

Update for OP

As for your follow-up:

Once I have the files in their local computer, how would the bring it into their current powershell session?

Remember that Import-Module, is about modules to be loaded that are already on your local machine, not modules from any local or remote repo. You still have to install the module form whatever repo you target.

If you module is properly defined, and installed on the local machine, if you are on PowerShell v3 and higher, Import-Module should not be needed, as when properly designed and implemented, they should autoload.

Specifically, your follow-up question is a duplicate of this Q&A How to install/update a PowerShell module from a local folder - set up an internal module repository

You should just have to do the normal steps to get and use the module from your repo.

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

Install-Module -Name 'MyModule'

Import-Module -Name 'MyModule'

See also:

Update-Module

postanote
  • 15,138
  • 2
  • 14
  • 25
  • Thanks. Once do this, how do I import my module into my current session of powershell? Would regular `Import-Module` would work? – iraSenthil May 01 '19 at 13:27