Skip to content

Instantly share code, notes, and snippets.

@codykonior
Last active February 21, 2018 04:13
Show Gist options
  • Save codykonior/7391faf43842767ac79cfbce5b038689 to your computer and use it in GitHub Desktop.
Save codykonior/7391faf43842767ac79cfbce5b038689 to your computer and use it in GitHub Desktop.
Find-ModuleUpdate
# Faster to get them all at once than look up a few dozen individually
$galleryModules = Find-Module -Verbose:$false
# If you only want to update modules sourced from the PowerShell Gallery, you can add a filter by:
# Where-Object { $_.RepositorySourceLocation -eq "https://www.powershellgallery.com/api/v2/" }
Get-Module -ListAvailable -Verbose:$false | Group-Object Name | ForEach-Object {
if (($_.Group | ForEach-Object Version | Select-Object -Unique | Measure-Object).Count -gt 1) {
Write-Verbose "$($_.Name) has multiple versions installed, I will only check the highest version"
}
$module = $_.Group | Sort-Object Version -Descending | Select-Object -First 1
$galleryModule = $galleryModules | Where-Object { $module.Name -eq $_.Name }
if (!$galleryModule) {
Write-Verbose "Could not find module $($module.Name) in the PowerShell Gallery"
} else {
if ($galleryModule.Version -gt $module.Version) {
"$($module.Name) by $($module.Author) @$($module.CompanyName) version $($module.Version) is outdated, $($galleryModule.Version) by $($galleryModule.Author) @$($galleryModule.CompanyName) is available"
} else {
Write-Verbose "$($module.Name) by $($module.Author) @$($module.CompanyName) version $($module.Version) is current"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment