Day 19: Creating your own online PowerShellGet repository

Welcome to Day 19 of the “100 Days of DevOps with PowerShell”! For background on our goals in this series, see Announcing the “100 Days of Devops with PowerShell” Series here at SCC.

Disclaimer: The code below is from PowerShell 5.0 July CTP release and could change or break when RTM is released.  I’ll endeavour to update this article where applicable.

In a Day 14 of this series we looked at how to discover and install modules using PowerShellGet and we saw that by default the module is set to use a Microsoft resource gallery at https://msconfiggallery.cloudapp.net/.  After finding how easy it is to discover and install modules with PowerShellGet, the obvious question is how can I create my own repositories?  If you have read Day 4 or Day 11, you will probably have noticed that the repositories for OneGet or PowerShellGet are based on NuGet package managers and therefore you need to create  your own NuGet server.   There are a couple of options here and both are fairly straight forward.  You can either host your own NuGet server or create one online, and in this article we will focus on creating your online PowerShellGet repository.

Creating Your Own Online Repository

There are a number of providers to choose from and the list includes:

MyGet

Inedo’s ProGet

JFrog’s Artifactory

 

All offer free online trails and in this example we are going to use MyGet.  After signing up, the first step is to create a feed which is going to be the URL to either find or publish your modules.

CreateFeed1

 

Clicking on Create a feed, you then need to provide the name, description and type of feed i.e. public, community or private. Once you’ve filled out the necessary details, click Create feed.

 

CreateFeed2

 

Add the New Repository to PowerShellGet

In this example my NuGet feed is https://www.myget.org/F/sccpowershell, but before I can use this with PowerShellGet I need to make some minor changes to update to the new NuGet feed URL.  In the latest CTP released in July (x64 or x86), the number of PowerShellGet modules increased from the original four cmdlets to  include three more cmdlets for managing the module source:

NewCmdlets

 

To update PowerShellGet to the new URL, lets try unregistering the the existing source

 

Unregister-ModuleSource : The module source ‘PSGallery’ cannot be unregistered.

No luck there, let’s try registering a new module source:

 

Now when we run Get-ModuleSource we have two source locations!

SoureLocations

So it would appear that it’s not possible to unregister the default module source by Microsoft.

Publishing  a Module to Your New Feed

With the additional module source, the next step is to publish a module to it.  In this current CTP release it would appear  in order to specify which feed the module should be published to you need to update the variable $PSGalleryPublishUri, but you must first load the module and then set the variable.  The reason for this is that each time the module loads it will set this value back to the default URL.

Note: the format of the $PSGalleryPublishUri URL should be your NuGet feed URL and append “api/v2/package” .  So in this case it will be ‘https://www.myget.org/F/sccpowershell/api/v2/package’

 

To publish a module you can either provide the name of the PowerShell module, assuming it’s located in one of the paths specified in $env:PSModulePath or you can provide a path to the module. In the example below I’m publishing a module called PowerShell Remote Registry which is already loaded on my machine and I can therefore just provide the name:

 

Now we are able to search specific repositories for a module and here we can see the module we’ve just published:

ListModulePublished

 

 

SIDEBAR: The NuGetApiKey is available under Access Tokens in your profile in MyGet or under your feed details.  Notice below that you can easily regenerate this key if you happen to publish it in plain text on the Internet!

 

NuGetAPIKey

 

Conclusion

Setting up your own PowerShellGet repository and publishing your modules is very straight forward and can be summarized in the steps below:

  1. Create your own online NuGet repository and feed
  2. Add the feed using Register-ModuleSource
  3. Update $PSGalleryPublishUri
  4. Publish your module using Publish-Module

 

I hope this has been useful and you can now start sharing PowerShell modules amongst your communities and organizations.

Previous Installments

To see the previous installments in this series, visit “100 Days of DevOps with PowerShell”.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.