Skip to content

Instantly share code, notes, and snippets.

@Splaxi
Created November 29, 2018 11:03
Show Gist options
  • Select an option

  • Save Splaxi/008e0ae70650af74d9d399b8dbe857b3 to your computer and use it in GitHub Desktop.

Select an option

Save Splaxi/008e0ae70650af74d9d399b8dbe857b3 to your computer and use it in GitHub Desktop.
Test all modules versions against PSGallery and Updated them
#Inspired from the work of Jack (@sharepointjack) - http://sharepointjack.com/2017/powershell-script-to-remove-duplicate-old-modules
#Will test all installed modules against the PSGallery and see if a never version is available.
#If newer version is available it will update it
$mods = Get-InstalledModule
foreach ($mod in $mods) {
Write-Host "Checking $($mod.name)"
$latestAvailable = Find-Module $mod.Name
if ($mod.version -eq $latestAvailable.version) {
$color = "green"
$text = "Latest available version match current installed"
}
else {
$color = "magenta"
$text = "Latest available version is higher than the current installed. Will install latest version "
}
Write-Host "$($mod.Name) - $($mod.version) [$text $($latestAvailable.version)]" -foregroundcolor $color
if($color -eq "magenta") {
Update-Module $mod.Name -Force
}
Write-Host "------------------------"
}
Write-Host "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment