Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell: Unable to update PowerShellGet , error: The version '1.4.7' of module 'PackageManagement' is currently in use

Tags:

powershell

Win10 laptop, in service for a couple years.

I have been stuck on this for a couple of days.

I try this command:

Install-Module –Name PowerShellGet –Force -AllowClobber

Which throws this error:

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

I can see in task manager there are no other sessions of powershell running.

I can exit all the sessions, and run this from a plain cmd:

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

And I get the SAME error.

OK, so I exit all powershell instances (as seen in Details tab of taskmgr) and do this:

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

And I get the same error.

So I do the uninstall again, (which runs without messages or errors). And I take out the big guns... powershell.exe is not running, and I navigate to:

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

And I delete the 1.4.7 directory.

And the commands above run with the same behavior and same error.

How do I move past this?

Additional Background:

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

Also Tried

Limiting scope to current user:

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.

SOLUTION

I did not track exactly the step, but one of the comments below led to a path that did resolve.

One of the tricks was to watch the process list, and to be sure that all vscode and other powershell-loading process were terminated prior to doing the update.

Apologies I cannot document the exact step that resolved. (I was kind of toast working on this.)

like image 919
Jonesome Reinstate Monica Avatar asked Feb 21 '21 17:02

Jonesome Reinstate Monica


People also ask

How do I know if PowerShellGet is installed?

The Get-InstalledModule cmdlet gets PowerShell modules that are installed on a computer using PowerShellGet. To see all modules installed on the system, use the Get-Module -ListAvailable command.

What is PowerShellGet?

PowerShellGet is a module with commands for discovering, installing, updating and publishing PowerShell artifacts like Modules, DSC Resources, Role Capabilities, and Scripts. The cmdlet reference documentation on this site documents the latest version of the module.

How do I update powershellget and PackageManagement?

Since both modules are part of the PowerShell Gallery, you can update them using a couple of simple commands. First lets check which versions of the modules you have available. If you use Update-Module, it will automatically load PowerShellGet and PackageManagement and list them as loaded PowerShell modules.

Why ‘powershellget’ module is not updating?

Update-Module : Module ‘PowershellGet' was not installed by using Install-Module, so it cannot be updated. How can I fix it? This is because PowerShellGet comes builtin with Windows 2016 but it's on older version. If you want all bells and whistles you need to install newest version from PowerShellGallery.

How do I update a preinstalled PowerShell module?

To update the preinstalled module you must use Install-Module. After you have installed the new version from the PowerShell Gallery, you can use Update-Module to install newer releases. PowerShellGet requires .NET Framework 4.5 or above. For more information, see Install the .NET Framework for developers.

Why can't I update powershellget without allowprerelease windows?

When trying to fix PowerShellGet lack of AllowPrerelease Windows actually blocked me from updating PowerShellGet which I knew is the reason why it fails in first place. Update-Module : Module ‘PowershellGet' was not installed by using Install-Module, so it cannot be updated.


1 Answers

I was able to fix this by running the command below in an admin PowerShell:

Update-Module -Name PowerShellGet -RequiredVersion 2.2.5

Hope this helps others!
Source: https://github.com/PowerShell/PowerShellGetv2/issues/599

like image 193
James Graham Avatar answered Oct 02 '22 10:10

James Graham