Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 8, 2025

PR Summary

Implements a new Reset-PSResourceRepository cmdlet that allows users to reset the repository store (PSRepositories.xml) to its default state with only PSGallery registered. This addresses the issue where users have no way to recover when the repository store becomes corrupted.

PR Context

When the PSResourceRepository.xml file becomes corrupted (e.g., through manual editing, file system errors, or incomplete writes), PSResourceGet cmdlets fail with XML parsing errors. Users were left with no built-in recovery mechanism and had to manually locate and delete the file, which is not user-friendly. This PR introduces a safe, built-in cmdlet to handle repository store reset with proper error handling and recovery mechanisms.

Key Features

  • Safety-first approach: Creates new file in temp location, validates, then replaces old file
  • Backup and restore mechanism: Automatically backs up existing file and restores if creation fails
  • ShouldProcess support: Implements -WhatIf and -Confirm with ConfirmImpact=High to ensure users understand the action
  • PassThru parameter: Returns PSGallery repository info after reset
  • Improved error messages: Updated CheckRepositoryStore() to suggest using Reset-PSResourceRepository when store is corrupted
  • Comprehensive error handling: All file operations include error handling with descriptive messages
  • Cross-volume compatibility: Uses Utils.MoveFiles() for file operations

Implementation Details

  • Reset method in RepositorySettings.cs: Safely creates a new PSRepositories.xml file with proper validation and error handling
  • ResetPSResourceRepository.cs: New cmdlet with ShouldProcess support
  • Test coverage: Added comprehensive test file with 6 test cases covering various scenarios
  • Module manifest: Added cmdlet to CmdletsToExport list
  • Latest changes: Merged with master branch to incorporate 17 recent commits

PR Checklist

Original prompt

This section details on the original issue you should resolve

<issue_title>Repository store (PSRepositories.xml) should have 'reset' functionality</issue_title>
<issue_description>### Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues.

Steps to reproduce

If the repository store gets corrupted, PSGet throws an error from attempting to parse the file. At the very least, error messaging should provide user with steps to remedy the situation. We should, however, also add either a new parameter or a new cmdlet that allows users to delete the old PSRepositories.xml file and create a new default file.

I'm proposing:
Register-PSResourceRepository -Reset
which, again, would delete the current PSRepositories.xml file, create a new one, and then register only the PowerShellGallery.

Expected behavior

If the xml file is unable to be parsed, an error throws telling the user that there was a parse error and suggesting to either try rerunning the command or running Register-PSResourceRepository -Reset to reset the repository store.

Actual behavior

Throws parse error and fails.

Error details

No response

Environment data

All versions and OS.

Visuals

No response</issue_description>

<agent_instructions>create a new cmdlet 'Reset-PSResourceRepository' that will create a new PSRepository.xml file. However, make sure that a new file is created first and once that new file is successfully created the old one is deleted. If the new file cannot be created, restore the old file. </agent_instructions>

Comments on the Issue (you are @copilot in this section)

@StevenBucher98 Adding some ShouldProcess logic in order to make sure the user understands what is happening and where the file is that they are going to reset @alerickson @mgreenegit consider documentation on how to handle a 'reset' scenario
Fixes #611

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

…ettings

Co-authored-by: alerickson <25858831+alerickson@users.noreply.github.com>
Copilot AI changed the title [WIP] Add reset functionality for PSRepositories.xml file Add Reset-PSResourceRepository cmdlet to recover from corrupted repository store Oct 8, 2025
Copilot AI requested a review from alerickson October 8, 2025 20:24
Copilot finished work on behalf of alerickson October 8, 2025 20:24
@alerickson
Copy link
Member

@copilot Add "'Reset-PSResourceRepository' in CmdletsToExport in Microsoft.PowerShell.PSResourceGet.psd1

Co-authored-by: alerickson <25858831+alerickson@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 21, 2025

@copilot Add "'Reset-PSResourceRepository' in CmdletsToExport in Microsoft.PowerShell.PSResourceGet.psd1

Added Reset-PSResourceRepository to CmdletsToExport in the module manifest in commit d7a00df.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 0t3vsblobprodcus362.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 (dns block)
  • 1k9vsblobprodcus379.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 (dns block)
  • 1s1vsblobprodcus386.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 (dns block)
  • 4myvsblobprodcus32.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 (dns block)
  • 51yvsblobprodcus36.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 (dns block)
  • 7devsblobprodcus323.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 (dns block)
  • 7k6vsblobprodcus337.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 (dns block)
  • 7tjvsblobprodcus341.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 (dns block)
  • 80zvsblobprodcus35.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 (dns block)
  • bcnvsblobprodcus378.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 (dns block)
  • c78vsblobprodcus322.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 (dns block)
  • dlbvsblobprodcus316.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 (dns block)
  • gbsvsblobprodcus365.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 (dns block)
  • kh4vsblobprodcus325.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 (dns block)
  • kmuvsblobprodcus389.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 (dns block)
  • l49vsblobprodcus358.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 (dns block)
  • m6xvsblobprodcus342.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 (dns block)
  • s4uvsblobprodcus326.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 (dns block)
  • tphvsblobprodcus375.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 (dns block)
  • uy6vsblobprodcus34.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 (dns block)
  • yttvsblobprodcus357.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of alerickson November 21, 2025 18:49
@alerickson
Copy link
Member

@copilot in 'Reset(PSCmdlet cmdletPassedIn, out string errorMsg)', instead of copying files, just move them

Co-authored-by: alerickson <25858831+alerickson@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 21, 2025

@copilot in 'Reset(PSCmdlet cmdletPassedIn, out string errorMsg)', instead of copying files, just move them

Updated the Reset method to use Utils.MoveFiles() instead of File.Copy() for all file operations in commit a2c0ca2. This provides better cross-volume compatibility and simplifies the code.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 0t3vsblobprodcus362.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • 1k9vsblobprodcus379.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • 1s1vsblobprodcus386.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • 7tjvsblobprodcus341.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • 80zvsblobprodcus35.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • c78vsblobprodcus322.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • kh4vsblobprodcus325.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • l49vsblobprodcus358.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • m6xvsblobprodcus342.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • uy6vsblobprodcus34.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • yttvsblobprodcus357.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of alerickson November 21, 2025 18:58
…ions

Co-authored-by: alerickson <25858831+alerickson@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 21, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 0t3vsblobprodcus362.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • 1k9vsblobprodcus379.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • 1s1vsblobprodcus386.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • 7tjvsblobprodcus341.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • 80zvsblobprodcus35.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • c78vsblobprodcus322.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • kh4vsblobprodcus325.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • l49vsblobprodcus358.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • m6xvsblobprodcus342.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • uy6vsblobprodcus34.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • yttvsblobprodcus357.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from alerickson November 21, 2025 19:04
Copilot finished work on behalf of alerickson November 21, 2025 19:04
Co-authored-by: alerickson <25858831+alerickson@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 21, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 0t3vsblobprodcus362.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • 1k9vsblobprodcus379.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • 1s1vsblobprodcus386.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • 7tjvsblobprodcus341.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • 80zvsblobprodcus35.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • c78vsblobprodcus322.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • kh4vsblobprodcus325.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • l49vsblobprodcus358.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • m6xvsblobprodcus342.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • uy6vsblobprodcus34.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • yttvsblobprodcus357.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of alerickson November 21, 2025 19:09
Copilot AI requested a review from alerickson November 21, 2025 19:09
@alerickson
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@alerickson alerickson self-requested a review November 21, 2025 23:12
@alerickson
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@alerickson
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@alerickson
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@alerickson
Copy link
Member

@copilot pull in changes from master

Copy link
Contributor Author

Copilot AI commented Dec 5, 2025

@copilot pull in changes from master

Merged master into the branch in commit fb8aef7. Successfully incorporated 17 commits from master with auto-merge of the module manifest. Build verified with no warnings or errors.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 0t3vsblobprodcus362.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • 1k9vsblobprodcus379.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • 1s1vsblobprodcus386.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • 7tjvsblobprodcus341.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • 80zvsblobprodcus35.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • c78vsblobprodcus322.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • kh4vsblobprodcus325.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • l49vsblobprodcus358.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • m6xvsblobprodcus342.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • uy6vsblobprodcus34.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)
  • yttvsblobprodcus357.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --configuration Debug --framework net472 --no-restore (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from alerickson December 5, 2025 20:41
Copilot finished work on behalf of alerickson December 5, 2025 20:41
…into copilot/add-reset-functionality-to-repository-store
@alerickson
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@alerickson alerickson merged commit e2bf4ee into master Dec 5, 2025
12 checks passed
@alerickson alerickson deleted the copilot/add-reset-functionality-to-repository-store branch December 5, 2025 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Repository store (PSRepositories.xml) should have 'reset' functionality

5 participants