Register-PSResourceRepository

Registers a repository for PowerShell resources.

Syntax

Register-PSResourceRepository
        [-Name] <String>
        [-Uri] <String>
        [-Trusted]
        [-Priority <Int32>]
        [-CredentialInfo <PSCredentialInfo>]
        [-PassThru]
        [-Force]
        [-WhatIf]
        [-Confirm]
        [<CommonParameters>]
Register-PSResourceRepository
        [-PSGallery]
        [-Trusted]
        [-Priority <Int32>]
        [-PassThru]
        [-Force]
        [-WhatIf]
        [-Confirm]
        [<CommonParameters>]
Register-PSResourceRepository
        -Repository <Hashtable[]>
        [-PassThru]
        [-Force]
        [-WhatIf]
        [-Confirm]
        [<CommonParameters>]

Description

The cmdlet registers a NuGet repository containing PowerShell resources.

Examples

Example 1

This example registers the repository with the Name of PoshTestGallery.

Register-PSResourceRepository -Name PoshTestGallery -Uri 'https://www.poshtestgallery.com/api/v2'
Get-PSResourceRepository -Name PoshTestGallery

Name             Uri                                          Trusted   Priority
----             ---                                          -------   --------
PoshTestGallery  https://www.poshtestgallery.com/api/v2         False         50

Example 2

This example registers the default PSGallery repository. Unlike the previous example, we can't use the Name and Uri parameters to register the PSGallery repository. The PSGallery repository is registered by default but can be removed. Use this command to restore the default registration.

Register-PSResourceRepository -PSGallery
Get-PSResourceRepository -Name 'PSGallery'

Name             Uri                                          Trusted   Priority
----             ---                                          -------   --------
PSGallery        https://www.powershellgallery.com/api/v2       False         50

Example 3

This example registers multiple repositories at once. To do so, we use the Repository parameter and provide an array of hashtables. Each hashtable can only have keys associated with parameters for the NameParameterSet or the PSGalleryParameterSet.

$arrayOfHashtables = @{
        Name = 'Local'
        Uri = 'D:/PSRepoLocal/'
        Trusted = $true
        Priority = 20
    },
    @{
        Name = 'PSGv3'
        Uri = 'https://www.powershellgallery.com/api/v3'
        Trusted = $true
        Priority = 50
    },
    @{
        PSGallery = $true
        Trusted = $true
        Priority = 10
    }
Register-PSResourceRepository -Repository $arrayOfHashtables
Get-PSResourceRepository

Name      Uri                                      Trusted Priority
----      ---                                      ------- --------
PSGallery https://www.powershellgallery.com/api/v2 True    10
Local     file:///D:/PSRepoLocal/                  True    20
PSGv3     https://www.powershellgallery.com/api/v3 True    50

Example 4

This example registers a repository with credential information to be retrieved from a registered SecretManagement vault. You must have the Microsoft.PowerShell.SecretManagement module installed and have a registered vault containing the stored secret. The format of the secret must match the requirements of the repository.

$parameters = @{
  Name = 'PSGv3'
  Uri = 'https://www.powershellgallery.com/api/v3'
  Trusted = $true
  Priority = 50
  CredentialInfo = [Microsoft.PowerShell.PSResourceGet.UtilClasses.PSCredentialInfo]::new(
    'SecretStore', 'TestSecret')
}
Register-PSResourceRepository @parameters
Get-PSResourceRepository | Select-Object * -ExpandProperty CredentialInfo

Name           : PSGv3
Uri            : https://www.powershellgallery.com/api/v3
Trusted        : True
Priority       : 50
CredentialInfo : Microsoft.PowerShell.PSResourceGet.UtilClasses.PSCredentialInfo
VaultName      : SecretStore
SecretName     : TestSecret
Credential     :

Parameters

-Confirm

Prompts you for confirmation before running the cmdlet.

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-CredentialInfo

A PSCredentialInfo object that includes the name of a vault and a secret that's stored in a Microsoft.PowerShell.SecretManagement store.

Type:Microsoft.PowerShell.PSResourceGet.UtilClasses.PSCredentialInfo
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Force

Overwrites a repository if it already exists.

Type:SwitchParameter
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Name

Name of the repository to be registered. Can't be PSGallery.

Type:String
Position:0
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-PassThru

When specified, displays the successfully registered repository and its information.

Type:SwitchParameter
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Priority

Specifies the priority ranking of the repository. Valid priority values range from 0 to 100. Lower values have a higher priority ranking. The default value is 50.

Repositories are sorted by priority then by name. When searching for resources across multiple repositories, the PSResourceGet cmdlets search the repositories using this sort order and return the first match found.

Type:Int32
Position:Named
Default value:50
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-PSGallery

When specified, registers PSGallery repository.

Type:SwitchParameter
Position:Named
Default value:False
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-Repository

Specifies an array of hashtables that contain repository information. Use this parameter to register multiple repositories at once. Each hashtable can only have keys associated with parameters for the NameParameterSet or the PSGalleryParameterSet.

Type:Hashtable[]
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-Trusted

Specifies whether the repository should be trusted.

Type:SwitchParameter
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Uri

Specifies the location of the repository to be registered. The value must use one of the following URI schemas:

  • https://
  • http://
  • ftp://
  • file://
Type:String
Position:1
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet isn't run.

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

Inputs

None

Outputs

Microsoft.PowerShell.PSResourceGet.UtilClasses.PSRepositoryInfo

By default, the cmdlet produces no output. When you use the PassThru parameter, the cmdlet returns a PSRepositoryInfo object.

Notes

Repositories are unique by Name. Attempting to register a repository with same name results in an error.