Register-PSResourceRepository
註冊 PowerShell 資源的存放庫。
語法
NameParameterSet (預設值)
Register-PSResourceRepository
[-Name] <string>
[-Uri] <string>
[-Trusted]
[-Priority <int>]
[-ApiVersion <PSRepositoryInfo+APIVersion>]
[-CredentialInfo <PSCredentialInfo>]
[-CredentialProvider <CredentialProvider>]
[-PassThru]
[-Force]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
PSGalleryParameterSet
Register-PSResourceRepository
-PSGallery
[-Trusted]
[-Priority <int>]
[-PassThru]
[-Force]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
MARParameterSet
Register-PSResourceRepository
-MicrosoftArtifactRegistry
[-Trusted]
[-Priority <int>]
[-PassThru]
[-Force]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
RepositoriesParameterSet
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
此範例會一次註冊多個存放庫。 若要這樣做,我們使用 Repository 參數,並提供哈希表陣列。 每個哈希表只能有與
$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 Container Registry -
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 Artifacts feed 時可用。 有效值為:
-
None- 未定義憑證提供者 -
AzArtifacts- 使用 Azure Artifacts 憑證提供者
如果你不使用這個參數,預設值就是 None。 若儲存庫 URL 包含 pkgs.dev.azure.com 或 pkgs.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 |
-MicrosoftArtifactRegistry
指定時,會以以下設定註冊預設 MicrosoftArtifactRegistry 儲存庫:
Name-MicrosoftArtifactRegistryUri-https://mcr.microsoft.com/-
Trusted- 沒錯 -
Priority- 40 -
ApiVersion- 容器登錄
預設情況下, MicrosoftArtifactRegistry 儲存庫會註冊為受信任儲存庫,優先權高於儲存庫本身 PSGallery 。
你不能用這個參數來重置現有的儲存庫。 用 Set-PSResourceRepository 來更改現有儲存庫的設定。
這個參數是在 Microsoft 新增的。PowerShell.PSResourceGet v1.3.0-preview1.
參數屬性
| 類型: | SwitchParameter |
| 預設值: | False |
| 支援萬用字元: | False |
| 不要顯示: | False |
| 別名: | 三月 |
參數集
MARParameterSet
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-Name
要註冊之存放庫的名稱。 不可能, PSGallery 或者 MicrosoftArtifactRegistry。
參數屬性
| 類型: | 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 儲存庫:
Name-PSGalleryUri-https://www.powershellgallery.com/api/v2-
Trusted- 錯誤 -
Priority- 50 -
ApiVersion- V2
預設情況下,該 PSGallery 儲存庫會註冊為不受信任儲存庫,優先權低於儲存庫本身 MicrosoftArtifactRegistry 。
如果倉庫已被移除,你可以用它來恢復預設註冊 PSGallery 。 你不能用這個參數來重置現有的儲存庫。 用 Set-PSResourceRepository 來更改現有儲存庫的設定。
參數屬性
| 類型: | SwitchParameter |
| 預設值: | False |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
PSGalleryParameterSet
| Position: | Named |
| 必要: | True |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-Repository
指定包含存放庫資訊的哈希表數位。 使用此參數一次註冊多個存放庫。 每個哈希表只能有與
參數屬性
| 類型: | |
| 預設值: | 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 物件。
備註
存放庫 Name是唯一的。 嘗試以相同名稱註冊存放庫會導致錯誤。