header image

Creating a PowerShellGet repository

Posted by: | January 4, 2015 Comments Off on Creating a PowerShellGet repository |

In this post – http://blogs.msmvps.com/richardsiddaway/2014/12/21/delivering-powershell-code-with-the-november-preview/ – I showed how to use PowerShellGet, which is a feature new to PowerShell 5.0 to install PowerShell modules. By default PowerShelget uses the PowerShell gallery at https://www.powershellgallery.com as its source.


I don’t feel comfortable installing modules direct from a public gallery so I want my own.  I suspect that many organizations will want to use their own module repository rather than something on the Internet over which they have no control.


There are a number of options for setting up your own gallery.

You could create an online nuget feed. This is described in this post from the PowerShell team:


You could create your own nuget repository – an example of doing this can be found here – http://learn-powershell.net/2014/04/11/setting-up-a-nuget-feed-for-use-with-oneget/


After reading http://asaconsultant.blogspot.no/2014/05/build-your-local-powershell- module.html I decided to start with ProGet (http://inedo.com/proget/pricing) as it seemed simple and was installed locally so I could take it with me to do demos.


To keep things even simpler I went with the free version and used the download that also  installs SQL Express. The installer also can create a service INEDOPROGETSVC to host the web service ProGet will use. Set the Service to use the LocalSystem account so that it can access the location to which the modules will be published.


The ProGet default feed is nuget but you want your own for this game.  Its not obvious how to do this but open Proget administration page – http://localhost:81/administration


I’m using port 81 as this is running on my DSC server.


Click manage feeds and you’ll find a button labelled Create New Feed. Press the button.

You have 3 choices

A nuget feed

A chocolately feed

a npm feed (private registry)

Lets go with nuget.


After supplying a name and description I went with the defaults to complete the feed creation.


At this point PowerShellget can’t see the new repository so you need to register it.

£> Register-PSRepository -Name PowerShellModules -SourceLocation http://localhost:81/nuget/PowerShellModules -Installati
onPolicy Trusted


And it now shows in my list of PowerShell repositories

£> Get-PSRepository | fl Name, SourceLocation

Name           : PSGallery
SourceLocation : https://www.powershellgallery.com/api/v2/

Name           : MSPSGallery
SourceLocation : http://search.microsoft.com/default.aspx

Name           : PowerShellModules
SourceLocation : http://localhost:81/nuget/PowerShellModules


You need to set a location to which modules will be published

Set-PSRepository -Name PowerShellModules -PublishLocation ‘http://localhost:81/nuget/PowerShellModules’


Now to try and publish a module.


I’m going to use the Pester module I downloaded in the previous article:


£> Publish-Module -Name Pester -NuGetApiKey "Admin:Admin" -Repository PowerShellModules -Verbose
VERBOSE: Repository details, Name = ‘PowerShellModules’, Location = ‘http://localhost:81/nuget/PowerShellModules’;
IsTrusted = ‘True’; IsRegistered = ‘True’.
VERBOSE: Repository details, Name = ‘PowerShellModules’, Location = ‘http://localhost:81/nuget/PowerShellModules’;
IsTrusted = ‘True’; IsRegistered = ‘True’.
VERBOSE: Repository details, Name = ‘PowerShellModules’, Location = ‘http://localhost:81/nuget/PowerShellModules’;
IsTrusted = ‘True’; IsRegistered = ‘True’.
VERBOSE: Module’Pester’ was found in ‘C:\Program Files\WindowsPowerShell\Modules\Pester’.
VERBOSE: Loading module from path ‘C:\Users\Richard\AppData\Local\Temp\409922302\Pester\Pester.psm1’.
VERBOSE: Repository details, Name = ‘PowerShellModules’, Location = ‘http://localhost:81/nuget/PowerShellModules’;
IsTrusted = ‘True’; IsRegistered = ‘True’.
VERBOSE: Repository details, Name = ‘PowerShellModules’, Location = ‘http://localhost:81/nuget/PowerShellModules’;
IsTrusted = ‘True’; IsRegistered = ‘True’.
VERBOSE: Using the specified source names : ‘PowerShellModules’.
VERBOSE: Getting the provider object for the OneGet Provider ‘NuGet’.
VERBOSE: The specified Location is ‘http://localhost:81/nuget/PowerShellModules’ and OneGetProvider is ‘NuGet’.
VERBOSE: Performing the operation "Publish-Module" on target "Version ‘3.2.0’ of module ‘Pester’".
VERBOSE: Successfully published module ‘Pester’ to the module publish location


The -NuGetApiKey "Admin:Admin"  is the default and you’d want to change that for a production system.


Finally test the repository contents

£> Find-Module -Repository PowerShellModules

Version    Name                                Repository
——-    —-                                ———-
3.2.0      Pester                              PowerShellModules

under: PowerShell v5, PowerShellGet

Comments are closed.