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.
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 https://github.com/powershell/powershellget."
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 1.0.0.1 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
Version
-------
2.8.5.208
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
Version
-------
2.2.5
PS C:\Users\Administrator> Get-PSRepository
Name InstallationPolicy SourceLocation
---- ------------------ --------------
PSGallery Untrusted https://www.powershellgallery.com/api/v2
PS C:\Users\Administrator> Get-Module powershellget,packageManagement -ListAvailable
目录: C:\Program Files\WindowsPowerShell\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 1.4.8.1 PackageManagement {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource...}
Binary 1.0.0.1 PackageManagement {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource...}
Script 2.2.5 PowerShellGet {Find-Command, Find-DSCResource, Find-Module, Find-RoleCapability...}
Script 1.0.0.1 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!