functions/Get-ChocoOutdatedPackages.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
35
36
37
38
39
40
41
42
<#
.SYNOPSIS
    Find outdated packages from a local machine
.DESCRIPTION
    Wrapper around choco outdated -r. Ignores pinned and unfound packages from sources
.EXAMPLE
PS C:\> Get-ChocoOutdatedPackages
 
Name CurrentVersion Version Pinned
---- -------------- ------- ------
chocolatey.extension 2.0.1 2.0.2 false
curl 7.64.0 7.64.1 false
GoogleChrome 73.0.3683.103 74.0.3729.131 false
 
#>

function Get-ChocoOutdatedPackages {
    [CmdletBinding()]
    param(
    )
        Write-Verbose "Getting local outdated packages"
        $OutdatedPackages = (choco outdated -r --ignore-pinned --ignore-unfound --timeout=60)
        if ($LASTEXITCODE -eq 1){
            Write-Verbose -Message 'Error getting outdated packages'
            $OutdatedPackages
            Exit
        }
        if ($LASTEXITCODE -eq 0){
            Write-Verbose -Message 'No new packages available. Exiting'
            Exit
        }
        else {
        foreach ($NewPackage in $OutdatedPackages){
            [PSCustomObject]@{
                Name = $NewPackage.Split('|')[0]
                CurrentVersion = $NewPackage.Split('|')[1]
                Version = $NewPackage.Split('|')[2]
                Pinned = $NewPackage.Split('|')[3]
            }
        }
    }
}