Cannot Use Newer Version of PowerShellGet in PowerShell 5.1.

Brass Contributor

I need to install the prerelease commands for MgGraph.  To do that I need to use the -allowprerelease parameter for Install-Module, which requires a newer version of PowerShellGet than, which comes with 5.1.  There are plenty of articles on how to do this, but no matter what I try, I can't get it to use the newer version.

  • I have followed the steps here and here.
  • I have .NET 4.8 installed.
  • I am using TLS 1.2
  • I am running 64-bit PowerShell
  • Used Install-Module PowerShellGet to install it side-by side with v1.0.0.1
  • Tried Update-Module PowerShellGet -force -allowclobber
  • Uninstalled and reinstalled PowerShellGet
  • Tried restarting PowerShell.
  • Tried Rebooting


You can see, for the 64-bit modules, the 2.2.5 version of PowerShellGet is listed before v1.0.0.1, which is supposed to mean it will use that version, but it's still not recognizing the -AllowPrerelease option, meaning it's still using v1.0.0.1.


What can I do from here?

5 Replies


Hello, my answer is to translate Chinese into English through Google translation service, please forgive me, I can't speak English.

I tried to run the command you mentioned using PowerShell5.1 on a brand new unconfigured Windows Server 2016, but I did not observe the exception you mentioned.
The book "Windows Server 2016 Automation with PowerShell Cookbook Second Edition" mentions that "PowerShellGet, formerly known as OneGet, is a module that provides you with an easy way to discover, install, and update PowerShell modules and scripts. It relies on packagmanagement module, and the packagmanagement module depends on NuGet. It is an open source project at"
I'm guessing you may not have updated NuGet.
Here are the commands I used and some output:

PS C:\Users\Administrator> Import-Module  powershellget
PS C:\Users\Administrator> Get-Module -Name powershellget

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script    powershellget                       {Find-Command, Find-DscResource, Find-Module, Find-RoleCapability...}

PS C:\Users\Administrator> Install-PackageProvider -Name NuGet -Force -Verbose

PS C:\Users\Administrator>#Here I run exit to reopen the PowerShell command line program

PS C:\Users\Administrator> Get-PackageProvider -Name nuget|Select-Object -Property version


PS C:\Users\Administrator> Install-Module -Name PowerShellGet -Verbose -Force
详细信息: 模块“PowerShellGet”已成功安装到路径“C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.5”中。

PS C:\Users\Administrator>#Here I run exit to reopen the PowerShell command line program

PS C:\Users\Administrator> Import-Module powershellget
PS C:\Users\Administrator> Get-Module -Name powershellget |Select-Object -Property version


PS C:\Users\Administrator> Get-PSRepository

Name                      InstallationPolicy   SourceLocation
----                      ------------------   --------------
PSGallery                 Untrusted  

PS C:\Users\Administrator>  Get-Module powershellget,packageManagement -ListAvailable

    目录: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script    PackageManagement                   {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource...}
Binary    PackageManagement                   {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource...}
Script     2.2.5      PowerShellGet                       {Find-Command, Find-DSCResource, Find-Module, Find-RoleCapability...}
Script    PowerShellGet                       {Install-Module, Find-Module, Save-Module, Update-Module...}

PS C:\Users\Administrator> Install-Module microsoft.graph.authentication -AllowPrerelease

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] 是(Y)  [A] 全是(A)  [N] 否(N)  [L] 全否(L)  [S] 暂停(S)  [?] 帮助 (默认值为“N”): a

PS C:\Users\Administrator>

PS C:\Users\Administrator>#Here I run exit to reopen the PowerShell command line program

PS C:\Users\Administrator> Import-Module microsoft.graph.authentication
PS C:\Users\Administrator> Get-Module microsoft.graph.authentication |fl

Name              : microsoft.graph.authentication
Path              : C:\Program Files\WindowsPowerShell\Modules\microsoft.graph.authentication\2.0.0\Microsoft.Graph.Authentication.psm1
Description       : Microsoft Graph PowerShell Authentication Module.
ModuleType        : Script
Version           : 2.0.0
NestedModules     : {Microsoft.Graph.Authentication}
ExportedFunctions : {Find-MgGraphCommand, Find-MgGraphPermission}
ExportedCmdlets   : {Add-MgEnvironment, Connect-MgGraph, Disconnect-MgGraph, Get-MgContext...}
ExportedVariables :
ExportedAliases   : {Connect-Graph, Disconnect-Graph, Invoke-GraphRequest, Invoke-MgRestMethod}

PS C:\Users\Administrator>


good luck!









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:






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 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.





I think you can refer to the about_Command_Precedence description, which describes how PowerShell determines the command to run.
You can use the prefix (-Prefix parameter of the Import-Module command) when manually importing the new PowerShellGet module, as follows:

Import-Module -Name PowerShellGet -Version "2.2.5" -Prefix now_psg
#I am using the version of PowerShellGet for demonstration, and the 2.2.5 version of PowerShellGet is not installed on the Windows system I am using now
Get-Module PowerShellGet|fl

Name              : PowerShellGet
Path              : C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\\PSModule.psm1
Description       : PowerShell module with commands for discovering, installing, updating and publishing the PowerShell artifacts like Modules, DSC Re
                    sources, Role Capabilities and Scripts.
ModuleType        : Script
Version           :
NestedModules     : {}
#Note here, the commands of this module are prefixed with now_psg ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
ExportedFunctions : {Find-now_psgCommand, Find-now_psgDscResource, Find-now_psgModule, Find-now_psgRoleCapability...}


In this way, you can use the install-now_psgModule command to install the modules you need

Hello everyone, and thanks for the responses! At the end of the day yesterday, at the prompting of a coworker, I just went into C:\Program Files\WindowsPowerShell\Modules\PowerShellGet and zipped up the folder (instead of just deleting it). PowerShell now only has the 2.2.5 folder and it is now using the new version of PowerShellGet :).

Does anyone know if the version is needed for anything at all?



best response confirmed by Ukiman1014 (Brass Contributor)

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.