Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup old module versions when upgrading powershell modules and --cleanup is specified #991

Open
soredake opened this issue Nov 30, 2024 · 0 comments
Labels
C-feature request New feature request

Comments

@soredake
Copy link

soredake commented Nov 30, 2024

I want to suggest a new step

  • Which tool is this about? Where is its repository?
  • Which operating systems are supported by this tool?
  • What should Topgrade do to figure out if the tool needs to be invoked?
  • Which exact commands should Topgrade run?
  • Does it have a --dry-run option? i.e., print what should be done and exit
  • Does it need the user to confirm the execution? And does it provide a --yes
    option to skip this step?

I want to suggest some general feature

Cleanup old module versions when upgrading powershell modules and --cleanup is specified, example powershell function to do this:

function Remove-OldModule {
  [CmdletBinding(SupportsShouldProcess)]
  param ()

  $Latest = Get-InstalledModule

  foreach ($module in $Latest) {
    $oldVersions = Get-InstalledModule -Name $module.Name -AllVersions | Where-Object { $_.Version -ne $module.Version }

    foreach ($oldVersion in $oldVersions) {
      if ($PSCmdlet.ShouldProcess("Module: $($module.Name) Version: $($oldVersion.Version)", "Uninstall")) {
        Uninstall-Module -Name $module.Name -RequiredVersion $oldVersion.Version -Verbose
      }
    }
  }
}

More information

https://luke.geek.nz/2021/06/18/remove-old-powershell-modules-versions-using-powershell/

@soredake soredake added the C-feature request New feature request label Nov 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature request New feature request
Projects
None yet
Development

No branches or pull requests

1 participant