Поделиться через


Register-PSResourceRepository

Registers a repository for PowerShell resources.

Синтаксис

NameParameterSet (по умолчанию)

Register-PSResourceRepository
    [-Name] <String>
    [-Uri] <String>
    [-Trusted]
    [-Priority <Int32>]
    [-ApiVersion <APIVersion>]
    [-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>]

Описание

The cmdlet registers a NuGet repository containing PowerShell resources.

Примеры

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, where SecretStore is the name of the vault and TestSecret is the name of the stored secret.

You must have the Microsoft.PowerShell.SecretManagement module installed, have a registered vault, and stored a secret within it. If setup correctly, the command Get-SecretInfo -Name 'TestSecret' would return the secret.

The format of the secret must match the requirements of the repository. In some instances, TestSecret might need storing as a PSCredential object with a username and password or token. In others it may need storing as a SecureString representing just the token.

$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     :

Параметры

-ApiVersion

Specifies the API version used by the repository. Valid values are:

  • V2 - uses the NuGet V2 API
  • V3 - uses the NuGet V3 API
  • ContainerRegistry - used for Azure Container Registry
  • Local - use this for file system based repositories
  • NugetServer - use this for NuGet.Server based repositories

The Register-PSResourceRepository cmdlet should automatically detect the API version. This parameter allows you to change the API version after you have registered a repository.

Свойства параметра

Тип:Microsoft.PowerShell.PSResourceGet.UtilClasses.PSRepositoryInfo+APIVersion
Default value:None
Допустимые значения:Unknown, V2, V3, Local, NugetServer, ContainerRegistry
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

NameParameterSet
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-Confirm

Prompts you for confirmation before running the cmdlet.

Свойства параметра

Тип:SwitchParameter
Default value:False
Поддерживаются подстановочные знаки:False
DontShow:False
Aliases:cf

Наборы параметров

(All)
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-CredentialInfo

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

Свойства параметра

Тип:Microsoft.PowerShell.PSResourceGet.UtilClasses.PSCredentialInfo
Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

NameParameterSet
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-Force

Overwrites a repository if it already exists.

Свойства параметра

Тип:SwitchParameter
Default value:False
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

(All)
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-Name

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

Свойства параметра

Тип:String
Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

NameParameterSet
Position:0
Обязательно:True
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-PassThru

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

Свойства параметра

Тип:SwitchParameter
Default value:False
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

(All)
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов: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.

Свойства параметра

Тип:Int32
Default value:50
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

NameParameterSet
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False
PSGalleryParameterSet
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-PSGallery

When specified, registers PSGallery repository.

Свойства параметра

Тип:SwitchParameter
Default value:False
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

PSGalleryParameterSet
Position:Named
Обязательно:True
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов: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.

Свойства параметра

Тип:

Hashtable[]

Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

RepositoriesParameterSet
Position:Named
Обязательно:True
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-Trusted

Specifies whether the repository should be trusted.

Свойства параметра

Тип:SwitchParameter
Default value:False
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

NameParameterSet
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False
PSGalleryParameterSet
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов: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://

Свойства параметра

Тип:String
Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

NameParameterSet
Position:1
Обязательно:True
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-WhatIf

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

Свойства параметра

Тип:SwitchParameter
Default value:False
Поддерживаются подстановочные знаки:False
DontShow:False
Aliases:wi

Наборы параметров

(All)
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

CommonParameters

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

Входные данные

None

Выходные данные

Microsoft.PowerShell.PSResourceGet.UtilClasses.PSRepositoryInfo

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

Примечания

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