Register-PSResourceRepository

注册 PowerShell 资源的存储库。

语法

NameParameterSet (默认值)

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

说明

该 cmdlet 注册包含 PowerShell 资源的 NuGet 存储库。

示例

示例 1

此示例使用 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

示例 2

此示例注册默认 PSGallery 存储库。 与前面的示例不同,我们不能使用 名称Uri 参数来注册 PSGallery 存储库。 默认情况下,PSGallery 存储库已注册,但可以删除。 使用此命令还原默认注册。

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

示例 3

此示例一次注册多个存储库。 为此,我们使用 存储库 参数并提供哈希表数组。 每个哈希表只能有与 NameParameterSetPSGalleryParameterSet的参数关联的键。

$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

示例 4

此示例使用要从已注册的 SecretManagement 文件库检索的凭证信息注册一个存储库,其中 SecretStore 是文件库的名称, TestSecret 是存储的密钥的名称。

您必须安装 Microsoft.PowerShell.SecretManagement 模块,注册文件库,并在其中存储密钥。 如果设置正确,该命令 Get-SecretInfo -Name 'TestSecret' 将返回密钥。

机密的格式必须与存储库的要求相匹配。 在某些情况下, TestSecret 可能需要存储为具有用户名和密码或令牌的 PSCredential 对象。 在其他情况下,它可能需要存储为仅表示令牌的 SecureString

$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

指定存储库使用的 API 版本。 有效值为:

  • V2 - 使用 NuGet V2 API
  • V3 - 使用 NuGet V3 API
  • ContainerRegistry - 用于 Azure 容器注册表
  • Local - 将此用于基于文件系统的存储库
  • NugetServer - 将此用于基于 NuGet.Server 的存储库

Register-PSResourceRepository cmdlet 应自动检测 API 版本。 此参数允许在注册存储库后更改 API 版本。

参数属性

类型:Microsoft.PowerShell.PSResourceGet.UtilClasses.PSRepositoryInfo+APIVersion
默认值:None
接受的值:V2, V3, Local, NugetServer, ContainerRegistry
支持通配符:False
不显示:False

参数集

NameParameterSet
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-Confirm

在运行 cmdlet 之前,提示你进行确认。

参数属性

类型:SwitchParameter
默认值:False
支持通配符:False
不显示:False
别名:cf

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-CredentialInfo

PSCredentialInfo 对象,其中包括保管库的名称和存储在 Microsoft.PowerShell.SecretManagement 存储中的机密。

参数属性

类型:Microsoft.PowerShell.PSResourceGet.UtilClasses.PSCredentialInfo
默认值:None
支持通配符:False
不显示:False

参数集

NameParameterSet
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-CredentialProvider

这是一个动态参数,用于指定仓库所需的凭证提供者。 该参数仅在注册仓库为 Azure 工件源时可用。 有效值为:

  • None - 未定义凭证提供者
  • AzArtifacts - 使用 Azure Artifacts Credential Provider

如果不使用该参数,默认值为 None。 如果仓库URL包含 pkgs.dev.azure.compkgs.visualstudio.com,命令会自动注册仓库, CredentialProvider 属性设置为 AzArtifacts

参数属性

类型:Microsoft.PowerShell.PSResourceGet.UtilClasses.CredentialProviderType
默认值:None
接受的值:None, AzArtifacts
支持通配符:False
不显示:False

参数集

NameParameterSet
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-Force

覆盖存储库(如果已存在)。

参数属性

类型:SwitchParameter
默认值:False
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-Name

要注册的存储库的名称。 不能 PSGallery

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

NameParameterSet
Position:0
必需:True
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-PassThru

指定后,显示已成功注册的存储库及其信息。

参数属性

类型:SwitchParameter
默认值:False
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-Priority

指定存储库的优先级排名。 有效的优先级值范围为 0 到 100。 较低的值具有更高的优先级排名。 默认值是 50

存储库按优先级排序,然后按名称排序。 跨多个存储库搜索资源时,PSResourceGet cmdlet 使用此排序顺序搜索存储库,并返回找到的第一个匹配项。

参数属性

类型:Int32
默认值:50
支持通配符:False
不显示:False

参数集

NameParameterSet
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False
PSGalleryParameterSet
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-PSGallery

指定后,PSGallery 存储库注册。

参数属性

类型:SwitchParameter
默认值:False
支持通配符:False
不显示:False

参数集

PSGalleryParameterSet
Position:Named
必需:True
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-Repository

指定包含存储库信息的哈希表数组。 使用此参数一次注册多个存储库。 每个哈希表只能有与 NameParameterSetPSGalleryParameterSet的参数关联的键。

参数属性

类型:

Hashtable[]

默认值:None
支持通配符:False
不显示:False

参数集

RepositoriesParameterSet
Position:Named
必需:True
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-Trusted

指定是否应信任存储库。

参数属性

类型:SwitchParameter
默认值:False
支持通配符:False
不显示:False

参数集

NameParameterSet
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False
PSGalleryParameterSet
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-Uri

指定要注册的存储库的位置。 该值必须使用以下 URI 架构之一:

  • https://
  • http://
  • ftp://
  • file://

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

NameParameterSet
Position:1
必需:True
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-WhatIf

显示 cmdlet 运行时会发生什么情况。 cmdlet 未能运行。

参数属性

类型:SwitchParameter
默认值:False
支持通配符:False
不显示:False
别名:无线

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

CommonParameters

此 cmdlet 支持通用参数:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 有关详细信息,请参阅 about_CommonParameters

输入

None

输出

Microsoft.PowerShell.PSResourceGet.UtilClasses.PSRepositoryInfo

默认情况下,cmdlet 不生成任何输出。 使用 PassThru 参数时,cmdlet 将返回 PSRepositoryInfo 对象。

备注

存储库通过 名称是唯一的。 尝试使用同名注册存储库会导致错误。