Register-PSResourceRepository
注册 PowerShell 资源的存储库。
语法
Register-PSResourceRepository
[-Name] <String>
[-Uri] <String>
[-Trusted]
[-Priority <Int32>]
[-ApiVersion <APIVersion>]
[-CredentialInfo <PSCredentialInfo>]
[-PassThru]
[-Force]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Register-PSResourceRepository
[-PSGallery]
[-Trusted]
[-Priority <Int32>]
[-PassThru]
[-Force]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
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
存储库。 与前面的示例不同,我们无法使用 Name 和 Uri 参数注册 PSGallery
存储库。 存储库 PSGallery
默认注册,但可以删除。 使用此命令还原默认注册。
Register-PSResourceRepository -PSGallery
Get-PSResourceRepository -Name 'PSGallery'
Name Uri Trusted Priority
---- --- ------- --------
PSGallery https://www.powershellgallery.com/api/v2 False 50
示例 3
此示例一次注册多个存储库。 为此,我们使用 Repository 参数并提供哈希表数组。 每个哈希表只能有与 NameParameterSet 或 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
示例 4
此示例使用要从已注册 的 SecretManagement 保管库检索的凭据信息注册存储库。 必须 安装 Microsoft.PowerShell.SecretManagement 模块,并具有包含存储机密的已注册保管库。 机密的格式必须与存储库的要求相匹配。
$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 APIv3
- 使用 NuGet V3 APIlocal
- 将此用于基于文件系统的存储库nugetServer
- 将此用于基于 NuGet.Server 的存储库
该 Register-PSResourceRepository
cmdlet 应自动检测 API 版本。 此参数允许在注册存储库后更改 API 版本。
Type: | Microsoft.PowerShell.PSResourceGet.UtilClasses.PSRepositoryInfo+APIVersion |
Accepted values: | unknown, v2, v3, local, nugetServer |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Confirm
提示你在运行 cmdlet 之前进行确认。
Type: | SwitchParameter |
Aliases: | cf |
Position: | Named |
Default value: | False |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-CredentialInfo
一个 PSCredentialInfo 对象,其中包含保管库的名称和存储在 Microsoft.PowerShell.SecretManagement 存储中的机密。
Type: | Microsoft.PowerShell.PSResourceGet.UtilClasses.PSCredentialInfo |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Force
覆盖存储库(如果已存在)。
Type: | SwitchParameter |
Position: | Named |
Default value: | False |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Name
要注册的存储库的名称。 不能是 PSGallery
。
Type: | String |
Position: | 0 |
Default value: | None |
Required: | True |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-PassThru
指定后,显示已成功注册的存储库及其信息。
Type: | SwitchParameter |
Position: | Named |
Default value: | False |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Priority
指定存储库的优先级排名。 有效的优先级值范围为 0 到 100。 较低的值具有更高的优先级排名。 默认值为 50
。
存储库按优先级排序,然后按名称排序。 跨多个存储库搜索资源时, PSResourceGet cmdlet 会使用此排序顺序搜索存储库,并返回找到的第一个匹配项。
Type: | Int32 |
Position: | Named |
Default value: | 50 |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-PSGallery
指定后,注册 PSGallery 存储库。
Type: | SwitchParameter |
Position: | Named |
Default value: | False |
Required: | True |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Repository
指定包含存储库信息的哈希表数组。 使用此参数一次注册多个存储库。 每个哈希表只能有与 NameParameterSet 或 PSGalleryParameterSet 的参数关联的键。
Type: | Hashtable[] |
Position: | Named |
Default value: | None |
Required: | True |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Trusted
指定是否应信任存储库。
Type: | SwitchParameter |
Position: | Named |
Default value: | False |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Uri
指定要注册的存储库的位置。 该值必须使用以下 URI 架构之一:
https://
http://
ftp://
file://
Type: | String |
Position: | 1 |
Default value: | None |
Required: | True |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-WhatIf
显示运行该 cmdlet 时会发生什么情况。 cmdlet 未运行。
Type: | SwitchParameter |
Aliases: | wi |
Position: | Named |
Default value: | False |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
输入
None
输出
Microsoft.PowerShell.PSResourceGet.UtilClasses.PSRepositoryInfo
默认情况下,cmdlet 不生成任何输出。 使用 PassThru 参数时,cmdlet 返回 PSRepositoryInfo 对象。
备注
存储库按 名称是唯一的。 尝试使用同名注册存储库会导致错误。
相关链接
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈