Skip to content

Uninstall-Module incorrectly claims other modules are dependent on the one being uninstalled #35

@matteo-prosperi

Description

@matteo-prosperi

Steps to reproduce

PS C:\WINDOWS\system32> Get-Module AWS.Tools.* -ListAvailable
PS C:\WINDOWS\system32> Install-Module AWS.Tools.Common -RequiredVersion 3.3.563.1 -force
PS C:\WINDOWS\system32> Install-Module AWS.Tools.EC2 -force
PS C:\WINDOWS\system32> Get-Module AWS.Tools.* -ListAvailable


    Directory: C:\Users\xxx\Documents\PowerShell\Modules

ModuleType Version    Name                                PSEdition ExportedCommands
---------- -------    ----                                --------- ----------------
Binary     3.3.604.0  AWS.Tools.Common                    Desk      {Clear-AWSHistory, Set-AWSHistoryConfiguration, Initialize-AWSDefaultConfiguration, Clear-AWSDefaultConfiguration…}
Binary     3.3.563.1  AWS.Tools.Common                    Desk      {Clear-AWSHistory, Set-AWSHistoryConfiguration, Initialize-AWSDefaultConfiguration, Clear-AWSDefaultConfiguration…}
Binary     3.3.604.0  AWS.Tools.EC2                       Desk      {Add-EC2CapacityReservation, Add-EC2ClassicLinkVpc, Add-EC2InternetGateway, Add-EC2NetworkInterface…}

PS C:\WINDOWS\system32> Uninstall-Module -Name AWS.Tools.Common -RequiredVersion 3.3.563.1
PackageManagement\Uninstall-Package : The module 'AWS.Tools.Common' of version '3.3.563.1' in module base folder 'C:\Users\xxx\Documents\PowerShell\Modules\AWS.Tools.Common\3.3.563.1' cannot be uninstalled, because one or more other modules 'AWS.Tools.EC2' are dependent on this module. Uninstall the modules that depend on this module before uninstalling module 'AWS.Tools.Common'.
At C:\Users\xxx\Documents\PowerShell\Modules\PowerShellGet\2.2.1\PSModule.psm1:12655 char:21
+ ...        $null = PackageManagement\Uninstall-Package @PSBoundParameters
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (Microsoft.PowerShel\u2026ts.UninstallPackage:UninstallPackage) [Uninstall-Package], Exception
+ FullyQualifiedErrorId : UnableToUninstallAsOtherModulesNeedThisModule,Uninstall-Package,Microsoft.PowerShell.PackageManagement.Cmdlets.UninstallPackage

PS C:\WINDOWS\system32> Uninstall-Module -Name AWS.Tools.Common -RequiredVersion 3.3.563.1 -Force
PS C:\WINDOWS\system32> Get-Module AWS.Tools.* -ListAvailable


    Directory: C:\Users\xxx\Documents\PowerShell\Modules

ModuleType Version    Name                                PSEdition ExportedCommands
---------- -------    ----                                --------- ----------------
Binary     3.3.604.0  AWS.Tools.Common                    Desk      {Clear-AWSHistory, Set-AWSHistoryConfiguration, Initialize-AWSDefaultConfiguration, Clear-AWSDefaultConfiguration…}
Binary     3.3.604.0  AWS.Tools.EC2                       Desk      {Add-EC2CapacityReservation, Add-EC2ClassicLinkVpc, Add-EC2InternetGateway, Add-EC2NetworkInterface…}

Expected behavior

I have three modules:

  • AWS.Tools.Common version 3.3.563.1
  • AWS.Tools.Common version 3.3.604.0
  • AWS.Tools.EC2 version 3.3.604.0 which depends on AWS.Tools.Common version 3.3.604.0

When running

Uninstall-Module -Name AWS.Tools.Common -RequiredVersion 3.3.563.1

I expect AWS.Tools.Common version 3.3.563.1 to be removed because no other module is dependent on this version.

Actual behavior

When running

Uninstall-Module -Name AWS.Tools.Common -RequiredVersion 3.3.563.1

I receive an error incorrectly claiming that AWS.Tools.EC2 depends on this module (it actually depends on a different version of AWS.Tools.Common).

If I use -Force the uninstall succeeds.

Environment data

PS C:\WINDOWS\system32> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.2.0
PSEdition                      Core
GitCommitId                    6.2.0
OS                             Microsoft Windows 10.0.17763
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
PS C:\WINDOWS\system32> Get-Module -ListAvailable PowerShellGet,PackageManagement


    Directory: C:\Users\xxx\Documents\PowerShell\Modules

ModuleType Version    Name                                PSEdition ExportedCommands
---------- -------    ----                                --------- ----------------
Script     1.4.5      PackageManagement                   Desk      {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource…}
Script     1.4.3      PackageManagement                   Desk      {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource…}
Script     2.2.1      PowerShellGet                       Desk      {Find-Command, Find-DSCResource, Find-Module, Find-RoleCapability…}
Script     2.2        PowerShellGet                       Desk      {Find-Command, Find-DSCResource, Find-Module, Find-RoleCapability…}

    Directory: C:\Program Files\PowerShell\Modules

ModuleType Version    Name                                PSEdition ExportedCommands
---------- -------    ----                                --------- ----------------
Script     1.4        PackageManagement                   Desk      {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource…}
Script     2.2        PowerShellGet                       Desk      {Find-Command, Find-DSCResource, Find-Module, Find-RoleCapability…}
Script     2.1.4      PowerShellGet                       Desk      {Find-Command, Find-DSCResource, Find-Module, Find-RoleCapability…}

    Directory: C:\program files\powershell\6\Modules

ModuleType Version    Name                                PSEdition ExportedCommands
---------- -------    ----                                --------- ----------------
Script     1.3.1      PackageManagement                   Desk      {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource…}
Script     2.1.2      PowerShellGet                       Desk      {Find-Command, Find-DSCResource, Find-Module, Find-RoleCapability…}
PS C:\WINDOWS\system32> Get-PackageProvider -ListAvailable

Name                     Version          DynamicOptions
----                     -------          --------------
NuGet                    3.0.0.1          Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag, Contains, AllowPrereleaseVersions, ConfigFile, SkipValidate
PowerShellGet            2.2.1.0          PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, InstallUpdate, NoPathUpdate, AllowPrereleaseVersions, Filter, Tag, Includes, DscResource, RoleCapability, Command, AcceptLicense, PublishLocation, ScriptSourceLocation, ScriptPublishLocation
PowerShellGet            2.2.0.0          PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, InstallUpdate, NoPathUpdate, AllowPrereleaseVersions, Filter, Tag, Includes, DscResource, RoleCapability, Command, AcceptLicense, PublishLocation, ScriptSourceLocation, ScriptPublishLocation
PowerShellGet            2.1.4.0
PowerShellGet            2.1.2.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions