Skip to content

Latest commit

 

History

History
362 lines (275 loc) · 8.93 KB

File metadata and controls

362 lines (275 loc) · 8.93 KB
external help file Module Name ms.custom ms.date online version schema
Microsoft.PowerShell.PSResourceGet.dll-Help.xml
Microsoft.PowerShell.PSResourceGet
1.0.2
11/10/2023
2.0.0

Register-PSResourceRepository

SYNOPSIS

Registers a repository for PowerShell resources.

SYNTAX

NameParameterSet (Default)

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

PSGalleryParameterSet

Register-PSResourceRepository [-PSGallery] [-Trusted] [-Priority <Int32>] [-PassThru] [-Force]
 [-WhatIf] [-Confirm] [<CommonParameters>]

RepositoriesParameterSet

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

-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
Parameter Sets: NameParameterSet
Aliases:

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

-Force

Overwrites a repository if it already exists.

Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases:

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

-Name

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

Type: System.String
Parameter Sets: NameParameterSet
Aliases:

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

-PassThru

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

Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: 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: System.Int32
Parameter Sets: NameParameterSet, PSGalleryParameterSet
Aliases:

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

-PSGallery

When specified, registers PSGallery repository.

Type: System.Management.Automation.SwitchParameter
Parameter Sets: PSGalleryParameterSet
Aliases:

Required: True
Position: Named
Default value: False
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: System.Collections.Hashtable[]
Parameter Sets: RepositoriesParameterSet
Aliases:

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

-Trusted

Specifies whether the repository should be trusted.

Type: System.Management.Automation.SwitchParameter
Parameter Sets: NameParameterSet, PSGalleryParameterSet
Aliases:

Required: False
Position: Named
Default value: 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: System.String
Parameter Sets: NameParameterSet
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Confirm

Prompts you for confirmation before running the cmdlet.

Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases: cf

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

-WhatIf

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

Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases: wi

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

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

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.

RELATED LINKS

Microsoft.PowerShell.SecretManagement