-
Notifications
You must be signed in to change notification settings - Fork 101
Description
Expected Behavior (Option 1)
There would be an additional switch (e.g. -AllowDuplicates) that could be specified on the Install-Module cmdlet call. The intent of this would be that this would prevent the cmdlet from raising an error/exception if there are the same versions of the same PSModule on multiple PSRepositories registered on a machine.
If there are multiple, registered PSRepositories on a machine (e.g. PSRepo1, PSRepo2, PSRepo3) that all (or at least two) have the same version of a PSModule (e.g. PSModuleXYZ), then when using/calling the Install-Module function without specifying any -Repository parameter value, but with specifing another switch (e.g. `-AllowDuplicates'), like so...
Install-Module 'PSModuleXYZ' -AllowDuplicates
... this should install the PSModuleXYZ PSModule, rather than raising an error that the same version exists in multiple repositories.
In a similar way, specifying multiple repositories (rather than none) should also install the PSModule from any of the repositories that has it (rather than erroring that, like so...
Install-Module 'PSModuleXYZ' -Repository 'PSRepo1', 'PSRepo2' -AllowDuplicates
..and not raise an exception.
The exact PSRepository (of the possible multiple ones) that the PSModule can be installed from could just be the first where it's available/found.
Expected Behavior (Option 2)
The alternative approach is to install from any available PSRepository as default (i.e. not use the additional switch in Opton 1) and also not throw the exception. This option may be less desired as it may be more likely to break existing processes and adds more risk to anyone currently using it (where this existing/current behaviour isn't desired).
Current Behavior
If a PSModule (e.g. PSModuleXYZ) exists on more than one PSRepository registered on a machine, when calling Install-Module like so...
Install-Module 'PSModuleXYZ'
...or...
Install-Module 'PSModuleXYZ' -RequiredVersion '1.2.3'
...will result in an error\exception (actually on the PackageManagement\Install-Package cmdlet) and prompt the user/caller to use the -Repository pararmeter, like so...
PackageManagement\Install-Package : Unable to install, multiple modules matched 'PSModuleXYZ'. Please specify a single -Repository.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1375 char:21
+ ... $null = PackageManagement\Install-Package @PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Exception
+ FullyQualifiedErrorId : DisambiguateForInstall,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
Possible Solution
There should be sufficient information in the "Expected Behaviour" sections to gauge an idea of possible implementation.
Context
In a large/exterprise organisation, it may be likely that there are multiple PSRepositories that exist on a machine, for example...
- PSGallery (Public Gallery)
- Company Internal (Production) PSRepositories
- Company Internal (Development) PSRepositories
- Personal/Private PSRepositories
- Others?
...and these may be duplicated to support 'High Availability' and/or performance requirements depending upon the architecture (i.e. Internal PSRepositories in different Geographical locations).
Certain machines don't have access to the internet (i.e. those in more secure environments) and/or access the public PSGallery (e.g. blocked by company/security policy) and as such, other, internal repositories may have to have a copy of public PSModules so they can be installed to these machines.
As a result, of the above it's more likely that there are going to be more machines with multiple PSRepositories registered on them and thus a higher chance of having the same version of the same module (or even different versions of the same module) across the PSRepositories.
I would also suggest that a reasonable assumption (in the majority of cases) that the same version of the same PSModule in one PSRepository should be identical to the same version of the same PSModule in another repository, and as a result, it shouldn't matter which PSRepository the PSModule is installed from.
In addition, depending upon the environment (e.g. Dev,Test,Production etc.), different PSRepositories may be registered on different machines and as a result, being specific about which PSRepository to install from is undesired - Install from any available would be preferable.
Your Environment
Name Value
---- -----
PSVersion 5.1.14409.1012
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14409.1012
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1