Register-PSResourceRepository
註冊 PowerShell 資源的存放庫。
Syntax
Register-PSResourceRepository
[-Name] <String>
[-Uri] <String>
[-Trusted]
[-Priority <Int32>]
[-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>]
Description
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
此範例會一次註冊多個存放庫。 若要這樣做,我們會使用 存放庫 參數並提供雜湊表的陣列。 每個雜湊表只能有與 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 :
參數
-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 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應