- Create an AWS EC2 instance with HashiCorp Terraform provider - Fri, Jul 29 2022
- Introduction to Docker Bind Mounts and Volumes - Mon, Oct 8 2018
- Managing Windows file shares with PowerShell - Mon, Aug 13 2018
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.
Now let's run the following command to see all the properties related to this repository.
Get-PSRepository -Name PSGallery | Select *
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.
Now we can run the following command to see the properties of the new file share repository:
Get-PSRepository -Name FileShareRepo | Select *
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:
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.
Thanks Matt
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?
Hi Eric, You could make use of Artifactory replication to mirror the entire repo to the local network.
This is nice but is there a way to automatically add the repository to computers in a domain by policy or something?
Hi,
There is an open issue pertaining to this requirement for having a machine level configuration that can be pushed to the Organization. As of now, the workaround is to have a logon script which configures the PSRepo, However this method also has its own limitations.
Secondly, If you are looking for an Enterprise Level package management solution, the Recommended solution is NuGet Feed/Server that can be used as PSRepo. Which has PM features such as indexing, scaling, webportal and so on.
More info on the same topic
https://4sysops.com/archives/how-to-create-a-nuget-feed-powershell-repository/
https://4sysops.com/archives/setting-up-nuget-server-to-host-your-own-nuget-feed-powershell-repository/
I’m trying to set this up right now for internal use (has to be a file share). And I am getting this error:
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.