Forum Discussion
Cannot Use Newer Version of PowerShellGet in PowerShell 5.1.
- May 19, 2023
The issue was that the X86 path was before the 64-bit one when I looked at $env:PSModulePath. (There was actually another path in there pointing to my documents folder - no idea where that came from.) So I reset $env:PSModulePath, making sure the 64-bit path was first (I just removed the others), and I'm all set.
So basically because I'm running 64-bit PowerShell, it was installing commands to the 64-bit path, but the environment variable was looking in the x86 folder first. I'm sure all of this had to do with old stuff I had done with PowerShell.
My experience is the same as gongyan's - I had no issues, either.
Since I already had the current PackageManagement module, I successfully ran the following as an administrator to install the newer PowerShellGet module:
Install-Module -Name PowerShellGet -Scope AllUsers -AllowClobber -Force
As an observation, I see you have x86 modules that I don't see (because I never work with x86) but in that context, we don't see the newer PowerShellGet. I can't help but wonder if for the test shown in your screenshot if you weren't actually (and perhaps accidentally) in an x86 shell?
What do you get back if you run the following "command"? If you see "x86" references then that will be your issue:
$PSGetPath
Example output from an x64 session:
Beyond that, I suspect if you ran "Get-Module -Name PowerShellGet" in that particular session you obtained the screenshot from, it'd reference the 1.0.0.1 version, which gets back to your original question: what can you do about it?
First, I'd verify that you are indeed in an x64 session, but assuming that you are, then at least verify the newer version of PowerShellGet actually works by explicitly importing the newer module:
Import-Module -Name PowerShellGet -Version 2.2.5
And then run your Install-Module -AllowPrerelease statement again - which should work or at least not fail for the "-AllowPrerelease" reason.
If that works but you still find that after starting a new x64 session that running the Install-Module command is not selecting the 2.2.5 module by default, then I'd recommend removing all PowerShellGet 2.2.5 versions (i.e. x86 and x64 from all user and machine scopes), close that session and then re-install it.
I'm not convinced the reinstallation is necessary or that it will change the outcome, as version selection is driven by the directory structure, but as far as I'm aware, there's also no alternative. The only reason for suggesting it is on the off-chance something in the module got corrupted during or after the module's installation. In other words, it's a long shot.
My gut feeling though is that you were inadvertently in an x86 session at that point in time.
Cheers,
Lain