Skip to content

Register-PSResourceRepository should support -Force #612

@Jaykul

Description

@Jaykul

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:

  1. Clear out existing registrations
  2. Separately re-register the PSGallery correctly
  3. 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:

  1. Put the PSGallery into my config file without the URL
  2. Separately re-register the PSGallery
  3. Register and Set 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)...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions