28

Win10 laptop, in service for a couple years.

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

8
  • Curious. 2.2.5 and 1.4.7 are the current versions for PowerShellGet / PackageManagement. If you append | % Path to your Get-Module call, you'll see the module-manifest locations. Without -ListAvailable, it'll show you which versions are currently loaded. You can unload with Remove-Module, then load one other than the one you're trying to update (pass the full manifest path to Import-Module), and try again. Commented Feb 21, 2021 at 18:21
  • @mklement0 OP updated with the path info thank you! Commented Feb 21, 2021 at 18:33
  • You can try to install in the scope of the current user, and optionally manually replace the directories in the all-users location later, manually. Try Install-Module -Name PowerShellGet -Force -Scope CurrentUser. That said - it looks like the installed versions are already current. Commented Feb 21, 2021 at 18:39
  • @mklement0 Thanks! Tried it. Get the same Warning. OP updated (See the bottom of the OP). I think I am giving up on this for now. Commented Feb 21, 2021 at 18:46
  • 2
    Upgrading/replacing these 2 modules is really a test of strength. What I've done is find and delete the modules in all locations, download the nuget packages for each from the psgallery website. Create the module folders in any of the $env:PSModulePath folder and version subfolder, and extract the contents of the nuget packages to those folders leaving me with only the newer versions that I've downloaded. Works as expected. Commented Feb 21, 2021 at 21:15

6 Answers 6

22

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

Update-Module -Name PowerShellGet -RequiredVersion 2.2.5.1

Hope this helps others!
Source: https://github.com/PowerShell/PowerShellGetv2/issues/599 Updated the version to 2.2.5.1 as the latest version on PowerShellGet Source: https://github.com/PowerShell/PowerShellGetv2/blob/master/CHANGELOG.md

Sign up to request clarification or add additional context in comments.

1 Comment

Update-Module helped me too
5

I'm using PS 7 and was having the same problem.

Steps I followed to fix the issue...:

  1. Listed module folders using $env:PSModulePath -split ';'. Result was list of paths where modules are stored as per scope (read here for more on the topic).

List of Paths:

   - 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. look for the folder called PackageManagement (it was in C:\Program Files\PowerShell\7\Modules in my case)
  2. Rename it (don't recommend deleting!)
  3. Get-InstalledModule to make sure I PackageManagement is not there anymore
  4. Install-Module -name PowerShellGet -RequiredVersion 2.2.5 -Force to install PowerShellGet.

and job's a good'un! At least for me :)

1 Comment

This solution worked for me. Thanks.
3

I don't have the rep to post a comment, but James Graham's post suggesting using the Update-Module worked for me too. Exact same issue, with the exact same version numbers, almost a year later. Yet, I just checked and there's now a 3.0.12 beta available which requires the code below:

Install-Module -Name PowerShellGet -AllowPrerelease -Force

I tried for a while to figure out the syntax highlighting but to no avail.

Comments

0

enter image description here

I had Two PowerShellGet Modules deployed to C:\Program Files\WindowsPowerShell\Modules\PowerShellGet , removing the 2.2.5 version fixed this for me

Comments

0

Was getting this error in PS 7.

Opened Windows PS 5.1 and did

Install-PackageProvider -Name NuGet -Force

Reboot.

Comments

0

Just went to C:\Program Files\PowerShell\7\Modules and renamed the PackageManagement folder.

Rename the command Install-Module -Name ExchangeOnlineManagement and it worked.

Verified with command: Get-InstalledModule -Name ExchangeOnlineManagement and it shows version 3.7.2 as of today.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.