-
Notifications
You must be signed in to change notification settings - Fork 100
Description
Summary of the new feature / enhancement
As a devops engineer, I want to be able to configure PSRepositories in a somewhat declarative Register-or-Set way, particularly during automation runs.
$Repositories = <# import a list from a psd1 file #> @{
Name = "OurGallery"
Url = "https://proget.OurDomain.com/nuget/PowerShell"
Trusted = $true
Priority = 90
}
Register-PSResourceRepository -Repositories $Repositories
The problem
Currently, if the repository exists, Register
fails, and I must use Set
but although I can use the same syntax with Set-PSResourceRepository
, in this case, if the repository does not already exist, it fails.
So I have to:
- Clear out existing registrations
- Separately re-register the PSGallery correctly
- Then register the other repositories we use
@('PSGallery') + $Repositories.Name | Unregister-PSResourceRepository
Register-PSResourceRepository -PSGallery -Priority 10
Register-PSResourceRepository -Repositories $Repositories
Or I have to:
- Put the PSGallery into my config file without the URL
- Separately re-register the PSGallery
Register
andSet
all the repositories, ignoring the errors
Register-PSResourceRepository -PSGallery
Register-PSResourceRepository -Repositories $Repositories -ErrorAction SilentlyContinue -ErrorVariable Failed
if ($Failed) {
Set-PSResourceRepository -Repositories $Repositories
}
Proposed technical implementation details
I'd like a -Force
switch on either Register or Set that would overwrite existing repositories (in the case of Register) or register them (in the case of Set) so that I can have declarative Register-or-Set syntax for the set of repositories I need, without needing the extra separate call to fix PSGallery, and the extra call to unregister the repositories before re-registering them (or set them after failing to register them)...