functions/Invoke-ChocoUpgradeIntPackage.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
43
44
45
<#
.SYNOPSIS
Takes PSobject to perform a choco upgrade an each package
.EXAMPLE
    PS C:\> $intpkgs = Invoke-ChocoInternalizePackage -PackageNames $Outdatedpkgs -Path $Path `
-PurgeWorkingDirectory | Where-Object { $_.Result -Like 'Internalize Success' }
 
PS C:\Chocotemp> Invoke-ChocoUpgradeIntPackage -PackageNames $intpkgs -Path $Path |
 Where-Object {$_.Result -eq 'Upgrade Success'}
 
Name Result Version NuGetpkgs
---- ------ ------- ---------
curl Upgrade Success 7.64.1 C:\Chocotemp\curl.7.64.1.nupkg
GoogleChrome Upgrade Success 74.0.3729.131 {C:\Chocotemp\chocolatey-core.extension.1.3.3.nupkg, C:\Chocotemp\GoogleChr...
 
#>

function Invoke-ChocoUpgradeIntPackage {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipeline=$True)]
        [pscustomobject[]]$PackageNames,
        [Parameter(Mandatory=$true)]
        [string]$Path
    )
    process {
        foreach ($Package in $PackageNames){
            Write-Verbose ("Upgrading " + $Package.Name)
            choco upgrade $Package.Name --source $Path --no-progress -y -r | Write-Verbose
            #If failure detected in output continue to next package
            if ($LASTEXITCODE -ne 0){
                $Result = 'Upgrade Failed'
            }
            else {
                $Result = 'Upgrade Success'
            }
                Write-Verbose ($Package.Name + ' Upgrade failed')
                [PSCustomObject]@{
                    Name = $Package.Name
                    Result = $Result
                    Version = $Package.Version
                    NuGetpkgs = $Package.NuGetpkgs
                 }
            }
        }
    }