PowerShell repositories
Each of the examples from the previous section uses the PowerShell Gallery as a source for installing modules. This is an important resource, but in a business setting, it may be desirable to restrict access to the gallery. Instead, an internal repository that holds curated or internally developed content may be implemented to share content.
Creating an SMB repository
A file share is a simple way to share content. Such a repository requires little effort to set up and maintain. A file share may be registered as a repository as follows:
$params = @{
Name = 'Internal'
SourceLocation = '\\server\share\directory'
InstallationPolicy = 'Trusted'
}
Register-PSRepository @params
Existing modules can be published to the repository using the Publish-Module
command. For example, if Pester 5.0.2 is installed, it may be published to the newly created internal repository:
$params = @{
Name = 'pester'
RequiredVersion = '5.0.2'
Repository = 'Internal'
}
Publish-Module @params
The RequiredVersion
parameter is mandatory if more than one version of the module (in this case Pester) exists on the system publishing the module. Once published, a nupkg
file will appear in the file share. The Pester module is now available for installation by anyone else with the repository registered.
Users installing content from an SMB share must be authenticated and must have at least read access to the share. Guest access may be granted to avoid the authentication requirement.
NuGet repositories
NuGet is a package manager for .NET. PowerShellGet
can use a NuGet repository as a source for PowerShell modules. The PowerShell Gallery is a NuGet repository.
NuGet offers greater flexibility when dealing with authentication, or package life cycles, when compared with SMB shares.
At the simple end, the Chocolatey.Server package available from chocolatey.org may be used to configure an Internet Information Services (IIS) website to act as a NuGet repository:
https://chocolatey.org/packages/chocolatey.server
About Chocolatey
Chocolatey is a package manager for Windows. See https://chocolatey.org for further information.
More advanced servers include Sonatype Nexus and ProGet. Both offer free to use servers, which may be locally deployed. These services must be configured, and once configured, packages will typically be published by using an API key to authenticate.