functions/Get-LatestChocoPackage.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function Get-LatestChocoPackage {
<#
 .SYNOPSIS
    Get the latest version of one or more packages from the Chocolatey community repository.
 .EXAMPLE
PS C:\Chocotemp> Get-LatestChocoPackage -PackageName googlechrome,firefox
 
Name CurrentVersion Version Pinned
---- -------------- ------- ------
GoogleChrome 75.0.3770.142 75.0.3770.142 No
Firefox 68.0.1 68.0.1 No
 
 
 #>

    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$true)]
        [string[]]$PackageNames
    )
    $PackageNames | ForEach-Object {
        $LatestPackage = (choco list $_ --exact --source=chocolatey -r)
        if ($LatestPackage){
            [PSCustomObject]@{
                Name = $LatestPackage.Split('|')[0]
                CurrentVersion = 'None'
                Version = $LatestPackage.Split('|')[1]
                Pinned = 'No'
            }
        }
        else {
            Write-Error "Could not find latest version of package $_"
        }
    }
}