PSResourceGet icon indicating copy to clipboard operation
PSResourceGet copied to clipboard

Cleanup functionality, where only the latest version of a module is kept

Open Jawz84 opened this issue 4 years ago • 10 comments

Summary of the new feature / enhancement

As a user/administrator I want to only keep the latest version of any module, so I don't accumulate many outdated versions on the systems that I manage.

Proposed technical implementation details (optional)

Functional implementation ideas

  1. Update-PsResource -KeepLatestOnly
  2. Uninstall-PsResource -KeepLatest

Technical idea The GetHelper class could be used and expanded to implement a filter returning all modules except the latest version. With that, the proper uninstalls could be performed (option 2) after installing the newest version (option 1).

Jawz84 avatar Dec 23 '21 20:12 Jawz84

vote++

Skatterbrainz avatar Dec 23 '21 21:12 Skatterbrainz

One issue here is you're going to need to check all existing modules for their requiredmodules and preserve any pinned versions as well, otherwise you're going to break those modules with this "cleanup". In addition, how are you going to know that a script doesn't require a pinned module that, upon doing this, will break that script?

JustinGrote avatar Dec 24 '21 00:12 JustinGrote

One issue here is you're going to need to check all existing modules for their requiredmodules and preserve any pinned versions as well, otherwise you're going to break those modules with this "cleanup". In addition, how are you going to know that a script doesn't require a pinned module that, upon doing this, will break that script?

Great point @JustinGrote! A rudimentary CheckIfDependency method is already in place, in the Uninstall-PsResource cmdlet, and probably needs to be expanded upon. The comment there suggests a database of installed PsResources, so a dependency check can be done quickly.

Jawz84 avatar Dec 24 '21 19:12 Jawz84

I'm fine with that risk, as long as the parameter is optional and comes with a warning.

Skatterbrainz avatar Dec 27 '21 16:12 Skatterbrainz

Related issue in regards to the DSC resource but still the same feature request: https://github.com/PowerShell/PowerShellGetDsc/issues/7

One issue here is you're going to need to check all existing modules for their requiredmodules and preserve any pinned versions as well, otherwise you're going to break those modules with this "cleanup". In addition, how are you going to know that a script doesn't require a pinned module that, upon doing this, will break that script?

Great point @JustinGrote! A rudimentary CheckIfDependency method is already in place, in the Uninstall-PsResource cmdlet, and probably needs to be expanded upon. The comment there suggests a database of installed PsResources, so a dependency check can be done quickly.

That method would also need to take into account installed script PSResources that have module dependencies.

ThomasNieto avatar Jan 02 '22 22:01 ThomasNieto

This brings up an age-old dilemma of whether the platform should police programmer habits, or if programmers should assume the responsibility of identifying dependencies properly. If there's a mechanism in place (or forthcoming) for developers to indicate dependencies, including version-level, then the developers should handle that risk. And even if I break another module (or script) by removing a dependent version, I can simply reinstall it.

Skatterbrainz avatar Jan 04 '22 12:01 Skatterbrainz

I think having this functionality with a confirm that dependencies are not (or not fully) taken into account would be a fine place to start from. Even if such a dependency management system is not implemented.

Jawz84 avatar Jan 04 '22 12:01 Jawz84

I will provide examples from various places that prove there is interest in this functionality:

  • http://sharepointjack.com/2017/powershell-script-to-remove-duplicate-old-modules/
  • https://4bes.nl/2021/09/19/update-all-powershell-modules-on-a-system/
  • https://github.com/yubu/ps.checkModuleUpdates/blob/08a51c7f95e39e7f34f422ce4e76a4dfd7185a24/ps.checkModuleUpdates.psm1#L68
  • https://github.com/microsoft/PFE/blob/b57a97d7c466d11a34420eeddd4af01e0f05c5a5/PowerShell/Scripts/AutoModuleInstallAndUpdate/AutoModuleInstallAndUpdate.ps1#L343
  • https://github.com/null-lex-null/posh/blob/4bd002fb631add4bafa56a986490248f54ba4364/apps/CleanupPackages.ps1
  • https://jawz84.wordpress.com/2018/08/22/how-to-clean-up-older-versions-of-installed-powershell-modules/ (yes, found I blogged about this myself, some years ago)

None of these solutions provide much dependency checking. Ofcourse it would be super cool if there was full dependency management, but in my opinion that can be implemented later.

Jawz84 avatar Jan 04 '22 13:01 Jawz84

| Assert-Duplicate -Near -Fuzzy $_ PowerShell/PowerShellGet#86

no-identd avatar Feb 08 '22 20:02 no-identd