Powershell:无法更新PowerShellGet,错误:当前正在使用模块“PackageManagement”的版本“1.4.7

4zcjmb1e  于 2023-03-18  发布在  Shell
关注(0)|答案(3)|浏览(205)

Win10笔记本电脑,在服务了几年。
我在这件事上纠结了好几天。

我尝试此命令:

Install-Module –Name PowerShellGet –Force -AllowClobber

引发此错误:

WARNING: The version '1.4.7' of module 'PackageManagement' 
is currently in use. Retry the operation after closing the applications.

我可以在任务管理器中看到没有其他powershell会话正在运行。
我可以退出所有会话,然后从一个普通的cmd运行此命令:

powershell -NoProfile -Command "Install-Module -Name PowerShellGet -Force -AllowClobber"

同样的错误

好的,我退出所有powershell示例(如taskmgr的Details选项卡所示)并执行以下操作:

powershell -NoProfile -Command "Uninstall-Module PowerShellGet"
powershell -NoProfile -Command "Install-Module -Name PowerShellGet -Force -AllowClobber"

同样的错误

所以我再次卸载,(运行时没有消息或错误)。然后我拿出大枪... powershelliderexe没有运行,我导航到:

C:\Users\$user\Documents\WindowsPowerShell\Modules\PackageManagement\1.4.7

然后删除1.4.7目录。
上面的命令运行时具有相同的行为和相同的错误。
我怎么才能忘掉这件事?

其他背景:

PS C:\WINDOWS\system32> Get-Module -ListAvailable PowerShellGet,PackageManagement

    Directory: C:\Program Files\WindowsPowerShell\Modules

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

PS C:\WINDOWS\system32>  Get-Module -ListAvailable PowerShellGet,PackageManagement | % path
C:\Program Files\WindowsPowerShell\Modules\PackageManagement\1.4.7\PackageManagement.psd1
C:\Program Files\WindowsPowerShell\Modules\PackageManagement\1.0.0.1\PackageManagement.psd1
C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.5\PowerShellGet.psd1
C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PowerShellGet.psd1

也尝试过

将范围限制为当前用户:

PS C:\WINDOWS\system32> Install-Module -Name PowerShellGet -Force -Scope CurrentUser
WARNING: The version '1.4.7' of module 'PackageManagement' is currently in use. Retry the operation after closing the
applications.
PS C:\WINDOWS\system32> exit

# OK, check taskmgr that all powershell.exe have exited, and run the below
C:\WINDOWS\system32>powershell -command "Install-Module -Name PowerShellGet -Force -Scope CurrentUser"
WARNING: The version '1.4.7' of module 'PackageManagement' is currently in use. Retry the operation after closing the
applications.

解决方案

我没有准确地跟踪这一步,但下面的一条评论引出了一条确实解决了问题的路径。
其中一个技巧是查看进程列表,并确保在进行更新之前终止所有vscode和其他powershell加载进程。
很抱歉,我不能记录下解决问题的确切步骤。(我在这方面的工作有点吐司。)

alen0pnh

alen0pnh1#

我能够通过在管理员PowerShell中运行下面的命令来修复此问题:

Update-Module -Name PowerShellGet -RequiredVersion 2.2.5.1

希望这对其他人有帮助!
来源:https://github.com/PowerShell/PowerShellGetv2/issues/599已将版本更新至2.2.5.1作为PowerShellGet来源:https://github.com/PowerShell/PowerShellGetv2/blob/master/CHANGELOG.md

jjhzyzn0

jjhzyzn02#

我没有代表发表评论,但是James Graham建议使用更新模块的帖子对我也起作用了。几乎一年后,完全相同的问题,完全相同的版本号。然而,我刚刚检查了一下,现在有一个3.0.12测试版可用,它需要下面的代码:

Install-Module -Name PowerShellGet -AllowPrerelease -Force

我尝试了一段时间来弄清楚语法突出显示,但无济于事。

4nkexdtk

4nkexdtk3#

我用的是PS 7,也遇到了同样的问题。
修复此问题所遵循的步骤...:
1.使用$env:PSModulePath -split ';'列出模块文件夹。结果是根据作用域(read here for more on the topic)存储模块的路径列表。
路径列表:

- C:\Users\**USER**\OneDrive - Microsoft\Documents\PowerShell\Modules
   - C:\ProgramFiles\PowerShell\Modules
   - **c:\program files\powershell\7\Modules**
   - C:\Program Files\WindowsPowerShell\Modules
   - C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
   - C:\Program Files (x86)\Microsoft Azure Information Protection\Powershell

1.查找名为PackageManagement的文件夹(在我的示例中,它位于C:\Program Files\PowerShell\7\Modules中)
1.重命名(不建议删除!)

  1. Get-InstalledModule以确保I PackageManagement不再存在
  2. Install-Module -name PowerShellGet -RequiredVersion 2.2.5 -Force来安装PowerShellGet。
    而且工作很棒!至少对我来说:)

相关问题