-
Notifications
You must be signed in to change notification settings - Fork 136
Find-Module error when updating PowerShellGet - Package Provider still loads 1.0.0.1 #246
Description
When updating PowerShellGet module to latest (1.6.0) from 1.0.0.1, and unloading 1.0.0.1, Find-Module -Name ModuleName
starts to fail with:
Find-Package : A parameter cannot be found that matches parameter name 'AllowPrereleaseVersions'. At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.6.0\PSModule.psm1:1609 char:34
+ PackageManagement\Find-Package @PSBoundParameters | Microsoft ...
Expected Behavior
PS C:\src> get-module PowerShellGet -list
Directory: C:\Program Files\WindowsPowerShell\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 1.0.0.1 PowerShellGet {Install-Module, Find-Module, Save-M...
PS C:\src> install-module PowerShellGet -Force
PS C:\src> Remove-module PowerShellGet
PS C:\src> import-module PowerShellGet -PassThru
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 1.6.0 PowerShellGet {Find-Command, Find-DscResource, Fin...
PS C:\src> find-module PackageManagement
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 1.1.7.0 PackageManagement {Find-Package, Find-PackageProvider,...
PS C:\src> Get-PackageProvider -Name PowerShellGet
Name Version DynamicOptions
---- ------- --------------
PowerShellGet 1.6.0.0 PackageManagementProvider, Type, Scope, AllowClobber...
Current Behavior
PS C:\src> get-packageProvider
Name Version DynamicOptions
---- ------- --------------
Chocolatey 2.8.5.130 SkipDependencies, ContinueOnFailure, ExcludeVersion,...
msi 3.0.0.0 AdditionalArguments
msu 3.0.0.0
NuGet 2.8.5.208 Destination, ExcludeVersion, Scope, SkipDependencies...
PowerShellGet 1.0.0.1 PackageManagementProvider, Type, Scope, AllowClobber...
Programs 3.0.0.0 IncludeWindowsInstaller, IncludeSystemComponent
PS C:\src> get-module PowerShellGet
PS C:\src> get-module PowerShellGet -list
Directory: C:\Program Files\WindowsPowerShell\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 1.0.0.1 PowerShellGet {Install-Module, Find-Module, Save-M...
PS C:\src> install-module PowerShellGet
Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to
install the modules from 'PSGallery'?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): y
WARNING: Version '1.0.0.1' of module 'PowerShellGet' is already installed at 'C:\Program
Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1'. To install version '1.6.0', run
Install-Module and add the -Force parameter, this command will install version '1.6.0' in
side-by-side with version '1.0.0.1'.
PS C:\src> install-module PowerShellGet -Force
PS C:\src> import-module PowerShellGet -Force
PS C:\src> Get-module PowerShellGet
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 1.0.0.1 PowerShellGet {Find-Command, Find-DscResource, Fin...
Script 1.6.0 PowerShellGet {Find-Command, Find-DscResource, Fin...
PS C:\src> remove-module PowerShellGet
PS C:\src> import-module PowerShellGet
PS C:\src> Get-module PowerShellGet
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 1.6.0 PowerShellGet {Find-Command, Find-DscResource, Fin...
PS C:\src> find-module PackageManagement
Find-Package : A parameter cannot be found that matches parameter name 'AllowPrereleaseVersions'. At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.6.0\PSModule.psm1:1609 char:34
+ PackageManagement\Find-Package @PSBoundParameters | Microsoft ...
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Find-Package], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.PackageManagement.Cmdl
ets.FindPackage
PS C:\src> Get-PackageProvider
Name Version DynamicOptions
---- ------- --------------
Chocolatey 2.8.5.130 SkipDependencies, ContinueOnFailure, ExcludeVersion,...
msi 3.0.0.0 AdditionalArguments
msu 3.0.0.0
NuGet 2.8.5.208 Destination, ExcludeVersion, Scope, SkipDependencies...
PowerShellGet 1.0.0.1 PackageManagementProvider, Type, Scope, AllowClobber...
Programs 3.0.0.0 IncludeWindowsInstaller, IncludeSystemComponent
PS C:\src> Import-PackageProvider -Name PowerShellGet -Force -RequiredVersion 1.6.0
Name Version DynamicOptions
---- ------- --------------
PowerShellGet 1.6.0.0 PackageManagementProvider, Type, Scope, AllowClobber...
PS C:\src> find-module PackageManagement
Version Name Repository Description
------- ---- ---------- -----------
1.1.7.0 PackageManagement PSGallery PackageManagemen...
Possible Solution
I found that the PackageProvider is not re-loaded, so one way to fix (for current session only) is to do:
Import-PackageProvider -Name PowerShellGet -Force -RequiredVersion 1.6.0
.
It seems that the PowerShellGet PackageProvider will still be defaulting to 1.0.0.1 for every process spun up from parent session (i.e. Start - Run - PowerShell).
Also, as long as PowerShellGet module v1.0.0.1 is installed, when loading PowerShellGet 1.6.0, Package Management, or leaving to Module autoloading, the Package Provider PowerShellGet 1.0.0.1 will always be loaded. And that is the worst part ;)
Steps to Reproduce (for bugs)
See the current behaviour section.
Context
This happened when updating the latest module of PackageManagement & PowerShellGet. It was relatively hard to troubleshoot because the error only refer to the Module(s), and when you check PackageManagement or PowerShellGet modules version they have the right Parameter. It does not mention the PowerShellGet PackageProvider.
The fact that the PackageProvider is persisted from the parent Session somehow made it harder to troubleshoot.
When logging on a machine, I'd have the error when doing Windows -> Start -> Runas /u:user PowerShell
, even if I'd had removed the PowerShellGet module v 1.0.0.1.
If I then did Start PowerShell from there, it would pick up the latest (on only installed) PowerShellGet module.
Your Environment
Tested on a Windows 7 with PSversion 5.1.14409.1012 and reproduced on the Windows 10 - Insider Preview Fast Ring system below
> PSVersionTable
Name Value
---- -----
PSVersion 5.1.17107.1000
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17107.1000
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
> Get-Module
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 0.0 chocolateyProfile {TabExpansion, Update-SessionEnviron... Manifest 3.1.0.0 Microsoft.PowerShell.Management {Add-Computer, Add-Content, Checkpoi... Manifest 3.1.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variabl... Binary 1.0.0.1 PackageManagement {Find-Package, Find-PackageProvider,... Script 1.1.7.0 PackageManagement {Find-Package, Find-PackageProvider,... Script 1.6.0
PowerShellGet {Find-Command, Find-DscResource, Fin... Script 1.2
PSReadline {Get-PSReadlineKeyHandler, Get-PSRea...
> Get-Module -ListAvailable PowerShellGet,PackageManagement
Directory: C:\Program Files\WindowsPowerShell\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 1.1.7.0 PackageManagement {Find-Package, Get-Package, Get-Pack...
Binary 1.0.0.1 PackageManagement {Find-Package, Get-Package, Get-Pack...
Binary 1.0.0.0 PackageManagement {Find-Package, Get-Package, Get-Pack...
Script 1.6.0 PowerShellGet {Install-Module, Find-Module, Save-M...
Script 1.0.0.1 PowerShellGet {Install-Module, Find-Module, Save-M...
> Get-PackageProvider
Name Version DynamicOptions
---- ------- --------------
Chocolatey 2.8.5.130 SkipDependencies, ContinueOnFailure, ExcludeVersion,...
msi 3.0.0.0 AdditionalArguments
msu 3.0.0.0
NuGet 2.8.5.208 Destination, ExcludeVersion, Scope, SkipDependencies...
PowerShellGet 1.6.0.0 PackageManagementProvider, Type, Scope, AllowClobber...
Programs 3.0.0.0 IncludeWindowsInstaller, IncludeSystemComponent
> Get-PackageProvider -ListAvailable
Name Version DynamicOptions
---- ------- --------------
Chocolatey 2.8.5.130 SkipDependencies, ContinueOnFailure, ExcludeVersion,... ChocolateyGet 1.0.0.1 AdditionalArguments
ContainerImage 0.6.4.0
msi 3.0.0.0 AdditionalArguments
msu 3.0.0.0
NuGet 2.8.5.208 Destination, ExcludeVersion, Scope, SkipDependencies...
PowerShellGet 1.6.0.0 PackageManagementProvider, Type, Scope, AllowClobber... PowerShellGet 1.0.0.1
Programs 3.0.0.0 IncludeWindowsInstaller, IncludeSystemComponent