Fix PowerShell modules always updating in CurrentUser scope - #5169
Merged
Gabriel Dufresne (GabrielDuf) merged 2 commits intoJul 22, 2026
Conversation
PowerShell 7 modules installed under AllUsers were always updated with `Update-PSResource -Scope CurrentUser`, installing a fresh CurrentUser copy and leaving the AllUsers version stale, so the update was detected again on every scan. The scope-detection and operation-helper logic were both correct, but `BaseNuGet.GetAvailableUpdates_UnSafe` built the update packages fresh from the GetUpdates() response without carrying the installed package's scope. The operation helper therefore fell back to CurrentUser. Carry the installed scope onto the update package (as Scoop already does). When a module is installed in both scopes, prefer the system-wide (AllUsers/Machine) copy so it never stays stale. Only PowerShell 7 is affected (`Update-PSResource` takes `-Scope`); PowerShell 5.x `Update-Module` has no `-Scope` and updates in place. Extract the scope-map building and update-response parsing into testable statics (`BuildInstalledScopeMap`, `ParseUpdatesResponse`) and add regression tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot started reviewing on behalf of
Gabriel Dufresne (GabrielDuf)
July 21, 2026 19:35
View session
Contributor
There was a problem hiding this comment.
Pull request overview
Preserves PowerShell module update scope when parsing NuGet update responses.
Changes:
- Maps installed package IDs to scopes, preferring Machine.
- Applies detected scopes to update packages.
- Adds PowerShell 7 regression tests.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
BaseNuGet.cs |
Adds scope mapping and scoped update parsing. |
PowerShell7ManagerTests.cs |
Tests Machine and CurrentUser update scopes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Copilot correctly noted the prefer-Machine heuristic paired a Machine scope with the last-enumerated (CurrentUser) version, and the max-version filter drops such entries anyway, so it did not actually fix the dual-scope case it implied. Make the scope map last-wins, matching the version map, so scope and installed version always come from the same enumerated package. A single-scope module (the reported #5163 case) still updates in its own scope. True per-scope updates for dual-scope installs would require scope-aware package identity, which the scope-blind upgrade loader does not support; that is a separate follow-up. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot started reviewing on behalf of
Gabriel Dufresne (GabrielDuf)
July 21, 2026 19:59
View session
Marc-André Moreau (mamoreau-devolutions)
approved these changes
Jul 21, 2026
Gabriel Dufresne (GabrielDuf)
deleted the
fix/5163-powershell-update-scope
branch
July 22, 2026 12:45
4 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request improves how NuGet-based package managers handle update detection and scope assignment, specifically addressing issues where PowerShell modules installed for "AllUsers" were not being updated correctly. The changes ensure that updates inherit the correct installation scope, preventing regressions where updates defaulted to the wrong user context. The update logic is now more robust and thoroughly tested.
Key improvements and fixes:
Update Detection and Scope Handling:
BaseNuGet.csto parse update responses using a newParseUpdatesResponsemethod, which ensures each update package carries the correct installed scope. This prevents updates from incorrectly defaulting to "CurrentUser" when the package was installed for "AllUsers".BuildInstalledScopeMaputility to map installed package IDs to their scopes, mirroring the version selection logic so that both version and scope are consistently determined.Testing and Regression Coverage:
PowerShell7ManagerTests.csto verify that update packages inherit the correct scope, including scenarios for "AllUsers", "CurrentUser", and packages installed in both scopes. These tests specifically guard against regressions.Code Maintenance:
BaseNuGet.csfor consistency and to support the new logic.