Skip to content

Instantly share code, notes, and snippets.

@DamianSuess
Last active October 22, 2018 17:32
Show Gist options
  • Save DamianSuess/6ef48243ef74666b0724ad11b53928e8 to your computer and use it in GitHub Desktop.
Save DamianSuess/6ef48243ef74666b0724ad11b53928e8 to your computer and use it in GitHub Desktop.
PS - Cleanup duplicate installed modules
write-host "Removing all older duplicate versions of installed modules";
write-host " 1. be sure to run this as an admin" -foregroundcolor yellow;
write-host " 2. (You can update all your Azure RM modules with update-module Azurerm -force)";
$mods = Get-InstalledModule;
foreach ($Mod in $mods)
{
write-host "Checking '$($mod.name)'";
$latest = Get-InstalledModule $mod.name;
$specificmods = Get-InstalledModule $mod.name -allversions;
write-host "$($specificmods.count) versions of this module found [ $($mod.name) ]";
foreach ($sm in $specificmods)
{
if ($sm.version -ne $latest.version)
{
write-host "uninstalling $($sm.name) - $($sm.version) [latest is $($latest.version)]";
$sm | Uninstall-Module -force;
write-host "Done uninstalling $($sm.name) - $($sm.version)";
}
}
write-host "------------------------";
}
write-host "Cleanup finished.";
write-host "Report of all duplicate installed modules";
write-host " 1. Always exec as an admin" -foregroundcolor yellow;
write-host " 2. (You can update all your Azure RMmodules with update-module Azurerm -force)";
$mods = Get-InstalledModule;
foreach ($Mod in $mods)
{
write-host "Checking $($mod.name)";
$latest = Get-InstalledModule $mod.name;
$specificmods = Get-InstalledModule $mod.name -allversions;
write-host "$($specificmods.count) versions of module found [ $($mod.name) ]";
foreach ($sm in $specificmods)
{
if ($sm.version -eq $latest.version)
{ $color = "green"; }
else
{ $color = "magenta"; }
write-host " $($sm.name) - $($sm.version) [highest installed is $($latest.version)]" -foregroundcolor $color;
}
write-host "------------------------";
}
write-host "Check finished.";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment