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

标签 powershell

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 session 正在运行。
我可以退出所有 session ,并从普通 cmd 运行它:
powershell -NoProfile -Command "Install-Module -Name PowerShellGet -Force -AllowClobber"
我得到了同样的错误。
好的,所以我退出所有 powershell 实例(如 taskmgr 的详细信息选项卡中所示)并执行以下操作:
powershell -NoProfile -Command "Uninstall-Module PowerShellGet"
powershell -NoProfile -Command "Install-Module -Name PowerShellGet -Force -AllowClobber"
我得到同样的错误。
所以我再次卸载,(运行时没有消息或错误)。然后我拿出大炮...... powershell.exe 没有运行,我导航到:
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 加载进程。
抱歉,我无法记录解决的确切步骤。 (我在这方面有点干杯。)

最佳答案

我可以通过在管理员 PowerShell 中运行以下命令来解决此问题:

Update-Module -Name PowerShellGet -RequiredVersion 2.2.5
希望这对其他人有帮助!

来源:https://github.com/PowerShell/PowerShellGetv2/issues/599

关于Powershell:无法更新 PowerShellGet ,错误:模块 '1.4.7' 的版本 'PackageManagement' 当前正在使用中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66305351/

相关文章:

windows - 我们如何在 Windows 的 git 目录上运行终端时随时显示分支名称?

powershell - 等于运算符的初学者问题

powershell - Powershell中的SyncRoot属性

powershell - PowerShell替换文件夹名称

powershell - 合并两个相似的 PSObject

postgresql - PSQL 不提示在 PowerShell 中输入密码

如果目录不存在,Powershell 'Move-Item' 不会创建目录

json - 比较和更新Json数组

powershell - 在powershell中定义字符串的单引号和双引号有什么区别

sql - 使用 Powershell 创建 SQL Server 用户