Private/Get-SpecPSGalleryLatestVersion.ps1

function Get-SpecPSGalleryLatestVersion {
    <#
    .SYNOPSIS
        Retrieves the latest version number of a specified PowerShell module from the PowerShell Gallery.
 
    .DESCRIPTION
        The Get-SpecPSGalleryLatestVersion function contacts the PowerShell Gallery to find the latest
        version number of the specified PowerShell module. It uses the Find-Module cmdlet from the PowerShellGet module
        to perform the search.
 
    .PARAMETER Module
        Specifies the name of the PowerShell module to search for in the PowerShell Gallery.
 
    .EXAMPLE
        Get-SpecPSGalleryLatestVersion -Module "ExampleModule"
        Returns the latest version number available in the PowerShell Gallery for the "ExampleModule" module.
 
    .EXAMPLE
        Get-SpecPSGalleryLatestVersion -Module "AnotherModule"
        Returns the latest version number available in the PowerShell Gallery for the "AnotherModule" module.
 
    .EXAMPLE
        Get-SpecPSGalleryLatestVersion -Module "NonExistentModule"
        Displays a warning message stating that the module "NonExistentModule" could not be found in the PowerShell Gallery.
 
    .NOTES
        Author: owen.heaume
        Version: 1.0 - initial function
    #>

    [cmdletbinding()]

    param (
        [string]$Module
    )

    write-verbose "Contacting PowerShell gallery for latest module version..."
    try {
        $result = (Find-Module -Name $module -ErrorAction Stop -ev x -Verbose:$false).Version
        return $result
    } catch {
        write-warning "Unable to find the module: $module"
        return $false
    }
}