Created
August 31, 2024 17:35
-
-
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.
This file contains hidden or 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
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