# script may require Administrator privileges if you want to remove # module versions installed in "AllUsers" scope
# find ALL modules with more than one version and/or location: $multiversion = Get-Module-ListAvailable | Group-Object-Property Name | Sort-Object-Property Name | Where-Object Count -gt1
# ask user WHICH of these modules to clean? $clean = $multiversion | Select-Object-Property@{N='Versions';E={$_.Count}}, @{N='ModuleName';E={$_.Name}} | Out-GridView-Title'Select module(s) to clean'-PassThru
# get the todo list with the modules the user wants to clean: $todo = $multiversion | Where-Object Name -in$clean.ModuleName
$todo | ForEach-Object { $module = $_.Name # list all versions of a given module and let the user decide which versions # to keep and which to remove: $_.Group | Select-Object-Property Version, ModuleBase, ReleaseNotes | Sort-Object-Property Version | Out-GridView-Title"Module $module : Select all versions that you want to remove"-PassThru | Select-Object-ExpandProperty ModuleBase | # do a last confirmation dialog before permanently deleting the subversions: Out-GridView-Title'Do you really want to permanently delete these folders? CTRL+A and OK to confirm'-PassThru | Remove-Item-Recurse-Force