Skip to content

Instantly share code, notes, and snippets.

@jorgeasaurus
Created August 31, 2024 17:35
Show Gist options
  • Save jorgeasaurus/011fbbe0bef8804b66cd4d155109c38e to your computer and use it in GitHub Desktop.
Save jorgeasaurus/011fbbe0bef8804b66cd4d155109c38e to your computer and use it in GitHub Desktop.
Check installed PowerShell modules against latest versions in a repository. Outputs detailed update status for easy management of outdated modules.
function Get-PSModuleUpdates {
param
(
[Parameter(ValueFromPipelineByPropertyName, Mandatory)]
[string]$Name,
[Parameter(ValueFromPipelineByPropertyName, Mandatory)]
[version]$Version,
[Parameter(ValueFromPipelineByPropertyName)]
[string]$Repository = 'PSGallery',
[switch]$OutdatedOnly
)
process {
try {
$latestVersion = [version](Find-Module -Name $Name -Repository $Repository -ErrorAction Stop).Version
$needsUpdate = $latestVersion -gt $Version
} catch {
Write-Warning "Error finding module $Name in repository $($Repository): $_"
return
}
if ($needsUpdate -or -not $OutdatedOnly) {
[PSCustomObject]@{
ModuleName = $Name
CurrentVersion = $Version
LatestVersion = $latestVersion
NeedsUpdate = $needsUpdate
Repository = $Repository
}
}
}
}
$Modules = Get-InstalledModule | Sort-Object Name | Get-PSModuleUpdates #-OutdatedOnly
$Modules | Format-Table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment