Skip to content

Fix Uninstall-PSResource blocking uninstall of a dependency version when a newer version satisfies a minimum-version requirement - #2021

Draft
Sydney Smith (SydneyhSmith) with Copilot wants to merge 4 commits into
masterfrom
copilot/fix-uninstall-dependent-module-failure
Draft

Fix Uninstall-PSResource blocking uninstall of a dependency version when a newer version satisfies a minimum-version requirement#2021
Sydney Smith (SydneyhSmith) with Copilot wants to merge 4 commits into
masterfrom
copilot/fix-uninstall-dependent-module-failure

Conversation

Copilot AI commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Uninstall-PSResource refuses to uninstall a package version if any installed module lists it as a dependency — but the check only compares the literal version number recorded in RequiredModules, without distinguishing an exact RequiredVersion from a minimum ModuleVersion/MaximumVersion range. As a result, uninstalling a version that satisfies a minimum-version dependency fails even when a newer installed version of the same package would still satisfy that dependency.

Root cause

  • CheckIfDependency in UninstallPSResource.cs treats any match between the version being uninstalled and the version recorded on the resolved RequiredModules entry as blocking, regardless of whether the requirement is a minimum version or an exact version.

Changes

  • Read the dependent module's raw manifest RequiredModules entry (via Import-PowerShellDataFile) to determine whether the requirement is an exact RequiredVersion or a range (ModuleVersion/MaximumVersion).
  • For range requirements, only block the uninstall if no other installed version of the package also satisfies the range. Exact RequiredVersion requirements keep the original blocking behavior.
  • Added IsAnotherInstalledVersionSatisfyingRequirement / GetRawRequiredModuleEntry helpers to encapsulate this logic.

Tests

  • Extended New-TestModule test helper with an optional -requiredModulesEntry parameter to author custom RequiredModules content.
  • Added Pester tests (local file-based repository, no external network dependency) covering:
    • Uninstalling a version that satisfies a minimum-version dependency succeeds when a newer installed version also satisfies it.
    • Uninstalling is still blocked when no other installed version satisfies the minimum-version requirement.

Example

# dbatools requires dbatools.library >= 2025.11.29.0 (ModuleVersion, not RequiredVersion)
# Both 2025.11.29 and 2025.12.4 of dbatools.library are installed
Uninstall-PSResource -Name dbatools.library -Version 2025.11.29
# Previously: blocked with "This package is a dependency for: 'dbatools, dbatools'"
# Now: succeeds, since 2025.12.4 still satisfies the minimum-version requirement

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI and others added 3 commits September 1, 2026 18:36
…ments

Co-authored-by: SydneyhSmith <43417619+SydneyhSmith@users.noreply.github.com>
Co-authored-by: SydneyhSmith <43417619+SydneyhSmith@users.noreply.github.com>
Co-authored-by: SydneyhSmith <43417619+SydneyhSmith@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix uninstallation issue for dependent module under newer version Fix Uninstall-PSResource blocking uninstall of a dependency version when a newer version satisfies a minimum-version requirement Sep 1, 2026
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.

Uninstall dependent module fails even when newer version is available

2 participants