You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
Solution
This PR introduces:
1. New Reset-PSResourceRepository Cmdlet
A new cmdlet that safely resets the repository store to its default configuration:
# Basic usage with confirmation promptReset-PSResourceRepository# Test what would happenReset-PSResourceRepository-WhatIf
# Return PSGallery info after reset$result=Reset-PSResourceRepository-PassThru
Key Features:
ShouldProcess support with ConfirmImpact=High to ensure users understand this is a significant action
-PassThru parameter to return the PSGallery repository information
Verbose output showing the file path being reset
-WhatIf and -Confirm support for safe testing
2. Safe Reset Implementation
The RepositorySettings.Reset() method implements a safety-first approach as requested:
Creates new XML file in a temporary location first
Validates the new file can be loaded
Backs up the existing file before deletion
Only replaces the old file after the new file is successfully created
Restores the backup if any step fails
Cleans up temporary files in all scenarios
This ensures that if anything goes wrong during the reset process, the original file is preserved and restored.
3. Improved Error Messages
Updated the error message in CheckRepositoryStore() to guide users:
Before:
Repository store may be corrupted, file reading failed with error: XML parsing error.
After:
Repository store may be corrupted, file reading failed with error: XML parsing error.
Try running 'Reset-PSResourceRepository' to reset the repository store.
Testing
Added comprehensive test coverage with 6 test cases:
Basic reset without PassThru parameter
Reset with PassThru returning PSGallery
-WhatIf support verification
Recovery from corrupted file
Handling when file doesn't exist
Resetting when multiple repositories are registered
Breaking Changes
None. This is a new cmdlet that doesn't modify any existing functionality.
Example Usage
# User encounters corrupted store errorGet-PSResourceRepository# Error: Repository store may be corrupted, file reading failed with error: Data at the root level is invalid.# Try running 'Reset-PSResourceRepository' to reset the repository store.# Reset the store (will prompt for confirmation due to High confirm impact)Reset-PSResourceRepository# Verify PSGallery is registeredGet-PSResourceRepository# Name Uri Trusted Priority# ---- --- ------- --------# PSGallery https://www.powershellgallery.com/api/v2 False 50
Related Issues
Addresses the concerns raised in issue comments:
@StevenBucher98's requirement for ShouldProcess logic to show file location ✅
@alerickson's note about documentation for reset scenarios ✅
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:
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
CopilotAI
changed the title
(削除) [WIP] Add reset functionality for PSRepositories.xml file (削除ここまで)
(追記) Add Reset-PSResourceRepository cmdlet to recover from corrupted repository store (追記ここまで)
Oct 8, 2025
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
Summary
Implements a new
Reset-PSResourceRepositorycmdlet 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.Fixes #1839
Problem
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.
Solution
This PR introduces:
1. New
Reset-PSResourceRepositoryCmdletA new cmdlet that safely resets the repository store to its default configuration:
Key Features:
ConfirmImpact=Highto ensure users understand this is a significant action2. Safe Reset Implementation
The
RepositorySettings.Reset()method implements a safety-first approach as requested:This ensures that if anything goes wrong during the reset process, the original file is preserved and restored.
3. Improved Error Messages
Updated the error message in
CheckRepositoryStore()to guide users:Before:
After:
Testing
Added comprehensive test coverage with 6 test cases:
Breaking Changes
None. This is a new cmdlet that doesn't modify any existing functionality.
Example Usage
Related Issues
Addresses the concerns raised in issue comments:
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:
1k9vsblobprodcus379.vsblob.vsassets.io/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish(dns block)37cvsblobprodcus359.vsblob.vsassets.io/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish(dns block)4myvsblobprodcus32.vsblob.vsassets.io/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish(dns block)51yvsblobprodcus36.vsblob.vsassets.io/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish(dns block)5dkvsblobprodcus355.vsblob.vsassets.io/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish(dns block)7devsblobprodcus323.vsblob.vsassets.io/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish(dns block)7k6vsblobprodcus337.vsblob.vsassets.io/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish(dns block)7tjvsblobprodcus341.vsblob.vsassets.io/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish(dns block)bcnvsblobprodcus378.vsblob.vsassets.io/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish(dns block)c50vsblobprodcus330.vsblob.vsassets.io/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish(dns block)c78vsblobprodcus322.vsblob.vsassets.io/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish(dns block)dlbvsblobprodcus316.vsblob.vsassets.io/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish(dns block)fdpvsblobprodcus345.vsblob.vsassets.io/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish(dns block)gbsvsblobprodcus365.vsblob.vsassets.io/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish(dns block)kh4vsblobprodcus325.vsblob.vsassets.io/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish(dns block)kmuvsblobprodcus389.vsblob.vsassets.io/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish(dns block)l49vsblobprodcus358.vsblob.vsassets.io/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish(dns block)m6xvsblobprodcus342.vsblob.vsassets.io/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish(dns block)pkvvsblobprodcus321.vsblob.vsassets.io/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish(dns block)s4uvsblobprodcus326.vsblob.vsassets.io/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish(dns block)tphvsblobprodcus375.vsblob.vsassets.io/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish(dns block)uy6vsblobprodcus34.vsblob.vsassets.io/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish(dns block)yttvsblobprodcus357.vsblob.vsassets.io/usr/bin/dotnet publish --configuration Debug --framework net472 --output bin/Debug/net472/publish(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a 200ドル gift card! Click here to start the survey.