Last active
February 5, 2026 04:34
-
-
Save aetos382/359883ac7078ff93c6f24bf8675129ce to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env pwsh | |
| #Requires -Module Microsoft.PowerShell.PSResourceGet | |
| function Find-UpgradablePSResource { | |
| param( | |
| [string] $Repository = 'PSGallery', | |
| [switch] $Prerelease) | |
| $newestModules = | |
| Get-Module -ListAvailable | | |
| Group-Object -Property Name, Author | | |
| ForEach-Object -Process { | |
| $_.Group | Sort-Object -Property Version -Descending -Top 1 | |
| } | |
| if ($newestModules.Count -eq 0) { | |
| return | |
| } | |
| $newestModuleTable = @{} | |
| foreach ($module in $newestModules) { | |
| $newestModuleTable[$module.Name] = $module | |
| } | |
| $findPSResourceParams = @{ | |
| Name = @($newestModuleTable.Keys) | |
| Repository = $Repository | |
| Type = 'Module' | |
| ErrorAction = 'Ignore' | |
| } | |
| if ($Prerelease) { | |
| $findPSResourceParams['Prerelease'] = $true | |
| } | |
| $candidateModules = | |
| Find-PSResource @findPSResourceParams | | |
| Where-Object -FilterScript { | |
| $installedModule = $newestModuleTable[$_.Name] | |
| return $_.Author -eq $installedModule.Author -and $_.Version -gt $installedModule.Version | |
| } | |
| foreach ($candidateModule in $candidateModules) { | |
| $installedModule = $newestModuleTable[$candidateModule.Name] | |
| $version = $candidateModule.AdditionalMetadata.NormalizedVersion | |
| if (!$version) { | |
| $version = $candidateModule.Version.ToString(3) | |
| } | |
| $result = [PSCustomObject] @{ | |
| Name = $installedModule.Namea | |
| Author = $installedModule.Author | |
| InstalledVersion = $installedModule.Version | |
| Path = $installedModule.Path | |
| AvailableVersion = $candidateModule.Version | |
| Description = $candidateModule.Description | |
| NewModuleUrl = "https://www.powershellgallery.com/packages/$($candidateModule.Name)/$($version)" | |
| } | |
| Write-Output $result | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment