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>]

说明

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

示例

示例 1

在此示例中,已注册 PoshTestGallery 存储库的 URI。 cmdlet Set-PSResourceRepository 用于将 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
  • local - 将此用于基于文件系统的存储库
  • nugetServer - 将此用于基于 NuGet.Server 的存储库

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

类型:Microsoft.PowerShell.PSResourceGet.UtilClasses.PSRepositoryInfo+APIVersion
接受的值:unknown, v2, v3, local, nugetServer
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 对象。