Last active
February 21, 2018 04:13
-
-
Save codykonior/7391faf43842767ac79cfbce5b038689 to your computer and use it in GitHub Desktop.
Find-ModuleUpdate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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