Please feel free to provide feedback or file bugs here.

Update-module needs flag to remove previous versions

When you run the Update-Module cmdlet there should be a flag to say update the module to the newest version and remove all previous versions. I understand the default being to leave existing versions, but if you DO really want to remove the older versions it becomes pretty painful when you start dealing with a suite of modules like AzureRM. Since each of the underlying modules are different versions it's not like you can easily just do a uninstall-module with a version restriction on all at the same time.

9 votes
Sign in
(thinking…)
Sign in with: Facebook Google
Signed in as (Sign out)

We’ll send you updates on this idea

Mike Wood shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →
declined  ·  J. Keith Bankston [MSFT] responded  · 

Wanted to update this thread with the current status and an approach that will allow uninstalling easily.

At this time we are not planning on implementing this feature. There are a large number of error conditions that can arise during an installation, and the general PS approach is not to add large numbers of parameters to support what are actually separate actions. In this case, the install and uninstall are separate.

The following command can be used (without the ending -Whatif) to clean up older versions of installed modules:
$Latest = Get-InstalledModule (modulename); Get-InstalledModule (modulename) -AllVersions | ? {$_.Version -ne $Latest.Version} | Uninstall-Module -WhatIf

4 comments

Sign in
(thinking…)
Sign in with: Facebook Google
Signed in as (Sign out)
Submitting...
  • Pavel Andreev commented  ·   ·  Flag as inappropriate

    Use this script to uninstall all old modules:

    $Latest = Get-InstalledModule
    foreach ($module in $Latest) {
    Get-InstalledModule $module.Name -AllVersions | ? {$_.Version -ne $module.Version} | Uninstall-Module -Verbose
    }

  • Anonymous commented  ·   ·  Flag as inappropriate

    I'd argue that the verb "update" inherently means "install new version and remove old version." If that wasn't the case, why not just use `install-module` to get a new module version?

  • Ferdinand Kuiper commented  ·   ·  Flag as inappropriate

    This would be a very nice option... Both actualy update with remove old versions and uninstall a rang of modules like AzureRM.

  • Mike Wood commented  ·   ·  Flag as inappropriate

    That would be helpful. It would be really nice to have the flag on the update-module so that you don't have to run the second command to remove the older version, but if you just made it super simple to keep only the newest version (especially across groups of modules that deploy together like the Azure CmdLets) that would be fine.

Feedback and Knowledge Base