Register PSRepository - PowerShell


Overview

Register-PSRepository registers a PowerShell repository from a specified location into the list of trusted repositories. This enables the installation, update, and publishing of PowerShell modules from the registered repository. It is particularly useful for managing private repositories within an organization or managing modules from external sources.

Syntax

Register-PSRepository [-SourceLocation] <string> [-Name] <string> [-Description] <string> [-InformationUri] <string> [-Credential] <PSCredential> [-TrustRepository] [-Force] [-WhatIf] [-Confirm]

Options/Flags

  • -SourceLocation: Specifies the location of the repository. It can be a local file path (e.g., C:\MyModules), a network share (e.g., \\server\share\modules), or a remote URI (e.g., https://mydomain.com/modules).
  • -Name: Sets a unique name for the repository. If omitted, the name will be derived from the source location.
  • -Description: Provides a description of the repository.
  • -InformationUri: Sets a URI for additional information about the repository.
  • -Credential: Specifies a credential object to access the repository if necessary.
  • -TrustRepository: Indicates that the repository should be trusted, allowing modules installed from it to be automatically imported.
  • -Force: Overwrites an existing repository with the same name.
  • -WhatIf: Performs a simulation of the command without making any changes.
  • -Confirm: Prompts for confirmation before executing the command.

Examples

Register a local repository:

Register-PSRepository -SourceLocation "C:\MyModules"

Register a remote repository:

Register-PSRepository -SourceLocation "https://mydomain.com/modules" -Name "MyRemoteRepo"

Register a trusted repository with credentials:

$cred = Get-Credential
Register-PSRepository -SourceLocation "\\server\share\modules" -Name "MyTrustedRepo" -Credential $cred -TrustRepository

Common Issues

  • Ensure the source location is accessible and contains valid PowerShell modules.
  • If using a remote repository, make sure it supports the necessary authentication and protocols.
  • Avoid registering malicious or untrusted repositories, as modules installed from them can compromise the system.

Integration

Combine Register-PSRepository with other commands to manage modules effectively:

  • Find-Module: Search for modules in registered repositories.
  • Install-Module: Install modules from registered repositories.
  • Update-Module: Update installed modules from registered repositories.
  • Unregister-PSRepository: Removes a registered repository from the list of trusted repositories.
  • Get-PSRepository: Retrieves information about registered repositories.
  • Publish-Module: Publishes a module to a registered repository.