Set-PSResourceRepository

设置已注册存储库的信息。

语法

Set-PSResourceRepository
   [-Name] <String>
   [-Uri <String>]
   [-Trusted]
   [-Priority <Int32>]
   [-ApiVersion <APIVersion>]
   [-CredentialInfo <PSCredentialInfo>]
   [-PassThru]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
Set-PSResourceRepository
   -Repository <Hashtable[]>
   [-PassThru]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]

说明

Set-PSResourceRepository cmdlet 设置已注册存储库的信息。

示例

示例 1

在此示例中,PoshTestGallery 存储库的 Uri 已注册。 Set-PSResourceRepository cmdlet 用于将 Uri 更改为本地路径。 PassThru 参数允许查看更改的存储库。

Get-PSResourceRepository -Name "PoshTestGallery"

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

Set-PSResourceRepository -Name "PoshTestGallery" -Uri "c:/code/testdir" -PassThru

Name             Uri                                          Trusted   Priority
----             ---                                          -------   --------
PoshTestGallery  file:///c:/code/testdir                        False         50

示例 2

此示例更改存储库 优先级受信任的 值。

注意

无法更改默认 PSGallery 存储库 URI 值。

Get-PSResourceRepository -Name "PSGallery"

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

Set-PSResourceRepository -Name "PSGallery" -Priority 25 -Trusted -PassThru

Name             Uri                                          Trusted   Priority
----             ---                                          -------   --------
PSGallery        https://www.powershellgallery.com/api/v2        True         25

示例 3

此示例使用 Repository 参数更改多个存储库的值。 该参数采用哈希表数组。 每个哈希表都包含要更新的存储库的信息。

Get-PSResourceRepository

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

$arrayOfHashtables = @{Name = "PSGallery"; Trusted = $True},
                     @{Name = "PoshTestGallery"; Uri = "c:/code/testdir"}
Set-PSResourceRepository -Repository $arrayOfHashtables -PassThru

Name             Uri                                          Trusted   Priority
----             ---                                          -------   --------
PSGallery        https://www.powershellgallery.com/api/v2        True         50
PoshTestGallery  file:///c:/code/testdir                        False         50

示例 4

此示例使用要从已注册的 Microsoft.PowerShell.SecretManagement 保管库检索凭据信息的存储库进行更新。 必须安装 Microsoft.PowerShell.SecretManagement 模块,并具有包含存储机密的已注册保管库。 机密的格式必须与存储库的要求相匹配。

$parameters = @{
  Name = "PoshTestGallery"
  Uri = "c:/code/testdir"
  CredentialInfo = [Microsoft.PowerShell.PowerShellGet.UtilClasses.PSCredentialInfo]::new(
    'SecretStore', 'TestSecret')
}
Set-PSResourceRepository @parameters -PassThru |
    Select-Object * -ExpandProperty CredentialInfo

Name           : PoshTestGallery
Uri            : file:///c:/code/testdir
Trusted        : False
Priority       : 50
CredentialInfo : Microsoft.PowerShell.PowerShellGet.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
接受的值:V2, V3, Local, NugetServer, ContainerRegistry
Position:Named
默认值:None
必需:False
接受管道输入:False
接受通配符:False

-Confirm

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

类型:SwitchParameter
别名:cf
Position:Named
默认值:False
必需:False
接受管道输入:False
接受通配符:False

-CredentialInfo

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

类型:Microsoft.PowerShell.PSResourceGet.UtilClasses.PSCredentialInfo
Position:Named
默认值:None
必需:False
接受管道输入:False
接受通配符:False

-Name

指定要修改的存储库的名称。

注意

无法更改默认 PSGallery 存储库 URI 值。

类型:String
Position:0
默认值:None
必需:True
接受管道输入:True
接受通配符:False

-PassThru

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

类型:SwitchParameter
Position:Named
默认值:False
必需:False
接受管道输入:False
接受通配符:False

-Priority

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

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

类型:Int32
Position:Named
默认值:50
必需:False
接受管道输入:False
接受通配符:False

-Repository

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

类型:Hashtable[]
Position:Named
默认值:None
必需:True
接受管道输入:False
接受通配符:False

-Trusted

指定是否应信任存储库。

类型:SwitchParameter
Position:Named
默认值:False
必需:False
接受管道输入:False
接受通配符:False

-Uri

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

  • https://
  • http://
  • ftp://
  • file://
类型:String
Position:Named
默认值:None
必需:False
接受管道输入:False
接受通配符:False

-WhatIf

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

类型:SwitchParameter
别名:wi
Position:Named
默认值:False
必需:False
接受管道输入:False
接受通配符:False

输入

String

输出

Microsoft.PowerShell.PSResourceGet.UtilClasses.PSRepositoryInfo

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