The PowerShell Gallery is a great place not only to download useful modules but also publish your own modules to share with the community. However, you may not necessarily intend all of your work for public consumption. In these cases, you can register an internal PowerShell repository to host your modules where you can control who has access and who can publish modules. If you don't have access to a robust NuGet feed internally, using file shares is a quick and easy way to get set up registering repositories in PowerShell with little effort.

You are probably already familiar with creating and configuring file shares to share files within your network. The same process applies for creating a file share to function as a PowerShell repository. Users will need to have read access to this file share at a minimum to register the repository and pull modules from it. Once you have created a new share and given the appropriate access to it, this share will host all the NuGet packages created when you publish modules to the repository.

Before I get started, I just wanted to mention that any changes you make to registered PowerShell repositories are going to be user specific. You'll have to make any changes for a particular user on a machine to any other users using that machine.

By default, you will have a repository registered for the PowerShell Gallery. You can see this by running Get-PSRepository.

Default PowerShell Gallery repository

Default PowerShell Gallery repository

Now let's run the following command to see all the properties related to this repository.

Get-PSRepository -Name PSGallery | Select *
PowerShell Gallery properties

PowerShell Gallery properties

For this article we are going to concentrate on the Name, SourceLocation, PublishLocation, and Installation Policy properties when creating a file share repository.

First, let's explore how to configure a file share PowerShell repository. This requires very little setup to get started since it only requires a file share and is a great option if you currently don't have access to an internal NuGet feed. In my environment I have a server called Server1 where I have created a file share called FileShareRepo. I have configured this share so the Everyone group has read and write access, but you may want to lock that down to specific users or groups.

To register this file share repository, I simply need to know the Universal Naming Convention (UNC) path to the share itself. Then I run the following command:

Register-PSRepository -Name FileShareRepo -SourceLocation '\\server1\FileShareRepo' ‑InstallationPolicy Trusted

Notice that I am setting the InstallationPolicy to Trusted since this is going to be an internal repository whose content I trust. If prompted to install a NuGet provider, type Y for Yes and hit Enter.

Registering a file share repository

Registering a file share repository

Now we can run the following command to see the properties of the new file share repository:

Get-PSRepository -Name FileShareRepo | Select *
Display the properties of the new file share repository

Display the properties of the new file share repository

You will notice the SourceLocation and PublishLocation are the same. For a file share repository, this should be fine.

Now that I have an internal file share repository set up, I'm going to go ahead and publish a module to the new repository. I have a module called TestModule installed on my machine, which I am going to publish using the Publish-Module command:

Publish-Module -Name TestModule -Repository FileShareRepo

The first time you publish a module, you may get a warning saying NuGet.exe is required when publishing to NuGet-based repositories, so go ahead and type Y for Yes and hit Enter.

Publishing a module to a file share repository

Let's run Find-Module against the new repository to see what we get back:

Finding modules on the new file share repository

Finding modules on the new file share repository

Find-Module returned the test module I just published to the file share repository.

Now that you've registered the internal file share repository, you may want to unregister the PowerShell Gallery for users so that only those internal repositories are available when finding and downloading modules. To unregister the PowerShell Gallery, you can simply run the Unregister-PSRepository command:

Unregister-PSRepository -Name PSGallery

If you ever need to get the PowerShell Gallery back, just run the following command:

Register-PSRepository -Default

I mentioned earlier I was setting my new repositories' Installation Policy to Trusted. You can change this for any of your currently registered repositories by using the Set-PSRepository command. I'm going to use it to set the PowerShell Gallery repository to Trusted:

Subscribe to 4sysops newsletter!

Set-PSRepository -Name PSGallery -InstallationPolicy Trusted

You can use Set-PSRepository to change any of the other properties of a currently registered repository as well.

  1. robin 4 years ago

    Thanks Matt

  2. Eric Periard 3 years ago

    Great tutorial, so now the PS Repo is set on the server, but as a next step I’d like to mirror the entire powershellgallery to the local repo for offline access for systems within my network, what would be the next step to look at?

    • Swapnil Kambli 3 years ago

      Hi Eric, You could make use of Artifactory replication to mirror the entire repo to the local network. 

  3. Gideon Terpstra 3 years ago

    This is nice but is there a way to automatically add the repository to computers in a domain by policy or something?

  4. David Figueroa 1 year ago

    I’m trying to set this up right now for internal use (has to be a file share). And I am getting this error:

    Publish-PSArtifactUtility : Failed to generate the compressed file for module 'C:\Program Files\dotnet\dotnet.exe
    failed to pack: error
    At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.5\PSModule.psm1:10990 char:17
    + ...             Publish-PSArtifactUtility @PublishPSArtifactUtility_Param ...
    +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [Write-Error], WriteErrorException
        + FullyQualifiedErrorId : FailedToCreateCompressedModule,Publish-PSArtifactUtility

    I’ve updated my PowershellGet to 2.2.5.
    It does not seem to have nuget.exe inside the module. (I downloaded a copy of nuget.exe just to see). I’m not sure where to go with this.

    Thanks for any help 🙂

    David F.

Leave a reply

Your email address will not be published.


© 4sysops 2006 - 2022


Please ask IT administration questions in the forums. Any other messages are welcome.


Log in with your credentials


Forgot your details?

Create Account