Creating Your Private PowerShellGet Repository

by Jul 19, 2016

PowerShell 3+ / PowerShellGet

In the previous tip we introduced PowerShellGet and showed how you can install this module from if you are using PowerShell 3.0 or 4.0 (it ships with 5.0). You also learned how you can use the cmdlets to find, download, and install modules from the public PowerShell Gallery.

Today, let’s register a simple file share-based private repository that you can use to safely exchange scripts and modules with your team colleagues:

# this is the name and location of our repository
# (adjust these details, and make sure the UNC path
# points to a file share that you have read and write
# permission)
$RepositoryName = 'Team1'
$path = '\\server1\myrepository'

# check to see that the target exists
$exists = Test-Path "filesystem::$path"
if (!$exists) { throw "Repository $path is offline" }

# check to see whether that location is registered already
$existing = Get-PSRepository -Name $RepositoryName -ErrorAction Ignore

# if not, register it
if ($existing -eq $null)
  Register-PSRepository -Name $RepositoryName -SourceLocation $path -ScriptSourceLocation $path -InstallationPolicy Trusted 

# list all registered repositories

Caveat: due to a bug in the current version of PowerShellGet, your UNC path may not contain spaces. This bug will be fixed soon.

Once your private repository is registered, you can use Publish-Script and Publish-Module to upload scripts and modules to your private repository. Other users that registered this repository can then use Find-Module, Install-Module, Update-Module, and all the other PowerShellGet cmdlets to use the uploaded content.

Twitter This Tip! ReTweet this Tip!