winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

Upgrade-WinGetPackage.ps1 (6504B)


      1 Function Upgrade-WinGetPackage
      2 {
      3     <#
      4         .SYNOPSIS
      5         Upgrades a package on the local system. 
      6         Additional options can be provided to filter the output, much like the search command.
      7         
      8         .DESCRIPTION
      9         By running this cmdlet with the required inputs, it will retrieve the packages installed on the local system.
     10 
     11         .PARAMETER Filter
     12         Used to search across multiple fields of the package.
     13         
     14         .PARAMETER Id
     15         Used to specify the Id of the package
     16 
     17         .PARAMETER Name
     18         Used to specify the Name of the package
     19 
     20         .PARAMETER Moniker
     21         Used to specify the Moniker of the package
     22 
     23         .PARAMETER Tag
     24         Used to specify the Tag of the package
     25         
     26         .PARAMETER Command
     27         Used to specify the Command of the package
     28 
     29         .PARAMETER Channel
     30         Used to specify the channel of the package. Note this is not yet implemented in Windows Package Manager as of version 1.1.0.
     31 
     32         .PARAMETER Scope
     33         Used to specify install scope (user or machine)
     34         
     35         .PARAMETER Exact
     36         Used to specify an exact match for any parameters provided. Many of the other parameters may be used for case-insensitive substring matches if Exact is not specified.
     37 
     38         .PARAMETER Source
     39         Name of the Windows Package Manager private source. Can be identified by running: "Get-WinGetSource" and using the source Name
     40 
     41         .PARAMETER Manifest
     42         Path to the manifest on the local file system. Requires local manifest setting to be enabled.
     43 
     44         .PARAMETER Interactive
     45         Used to specify the installer should be run in interactive mode.
     46 
     47         .PARAMETER Silent
     48         Used to specify the installer should be run in silent mode with no user input.
     49 
     50         .PARAMETER Locale
     51         Used to specify the locale for localized package installer.
     52 
     53         .PARAMETER Log
     54         Used to specify the location for the log location if it is supported by the package installer.
     55 
     56         .PARAMETER Override
     57         Used to override switches passed to installer.
     58 
     59         .PARAMETER Force
     60         Used to force the upgrade when the Windows Package Manager would ordinarily not upgrade the package.
     61 
     62         .PARAMETER Location
     63         Used to specify the location for the package to be upgraded.
     64 
     65         .PARAMETER Header
     66         Used to specify the value to pass as the "Windows-Package-Manager" HTTP header for a REST source.
     67 
     68         .PARAMETER Version
     69         Used to specify the Version of the package
     70 
     71         .PARAMETER VerboseLog
     72         Used to provide verbose logging for the Windows Package Manager.
     73         
     74         .PARAMETER AcceptPackageAgreement
     75         Used to accept any source package required for the package.
     76 
     77         .PARAMETER AcceptSourceAgreement
     78 
     79         .EXAMPLE
     80         Upgrade-WinGetPackage -id "Publisher.Package"
     81 
     82         This example expects only a single package containing "Publisher.Package" as a valid identifier.
     83 
     84         .EXAMPLE
     85         Upgrade-WinGetPackage -id "Publisher.Package" -source "Private"
     86 
     87         This example expects the source named "Private" contains a package with "Publisher.Package" as a valid identifier.
     88 
     89         .EXAMPLE
     90         Upgrade-WinGetPackage -Name "Package"
     91 
     92         This example expects the source named "Private" contains a package with "Package" as a valid name.
     93     #>
     94 
     95     PARAM(
     96         [Parameter(Position=0)] $Filter,
     97         [Parameter()]           $Name,
     98         [Parameter()]           $Id,
     99         [Parameter()]           $Moniker,
    100         [Parameter()]           $Source,
    101         [Parameter()] [ValidateSet("User", "Machine")] $Scope,
    102         [Parameter()] [switch]  $Interactive,
    103         [Parameter()] [switch]  $Silent,
    104         [Parameter()] [string]  $Version,
    105         [Parameter()] [switch]  $Exact,
    106         [Parameter()] [switch]  $Override,
    107         [Parameter()] [System.IO.FileInfo]  $Location,
    108         [Parameter()] [switch]  $Force,
    109         [Parameter()] [ValidatePattern("^([a-zA-Z]{2,3}|[iI]-[a-zA-Z]+|[xX]-[a-zA-Z]{1,8})(-[a-zA-Z]{1,8})*$")] [string] $Locale,
    110         [Parameter()] [System.IO.FileInfo]  $Log, ## This is a path of where to create a log.
    111         [Parameter()] [switch]  $AcceptSourceAgreements
    112     )
    113     BEGIN
    114     {
    115         [string[]] $WinGetArgs  = "Install"
    116         IF($PSBoundParameters.ContainsKey('Filter')){
    117             $WinGetArgs += $Filter
    118         }
    119         IF($PSBoundParameters.ContainsKey('Name')){
    120             $WinGetArgs += "--Name", $Name
    121         }
    122         IF($PSBoundParameters.ContainsKey('Id')){
    123             $WinGetArgs += "--Id", $Id
    124         }
    125         IF($PSBoundParameters.ContainsKey('Moniker')){
    126             $WinGetArgs += "--Moniker", $Moniker
    127         }
    128         IF($PSBoundParameters.ContainsKey('Source')){
    129             $WinGetArgs += "--Source", $Source
    130         }
    131         IF($PSBoundParameters.ContainsKey('Scope')){
    132             $WinGetArgs += "--Scope", $Scope
    133         }
    134         IF($Interactive){
    135             $WinGetArgs += "--Interactive"
    136         }
    137         IF($Silent){
    138             $WinGetArgs += "--Silent"
    139         }
    140         IF($PSBoundParameters.ContainsKey('Locale')){
    141             $WinGetArgs += "--locale", $Locale
    142         }
    143         if($PSBoundParameters.ContainsKey('Version')){
    144             $WinGetArgs += "--Version", $Version
    145         }
    146         if($Exact){
    147             $WinGetArgs += "--Exact"
    148         }
    149         if($PSBoundParameters.ContainsKey('Log')){
    150             $WinGetArgs += "--Log", $Log
    151         }
    152         if($PSBoundParameters.ContainsKey('Override')){
    153             $WinGetArgs += "--override", $Override
    154         }
    155         if($PSBoundParameters.ContainsKey('Location')){
    156             $WinGetArgs += "--Location", $Location
    157         }
    158         if($Force){
    159             $WinGetArgs += "--Force"
    160         }
    161     }
    162     PROCESS
    163     {
    164         ## Exact, ID and Source - Talk with Demitrius tomorrow to better understand this.
    165         $Result = Find-WinGetPackage -Filter $Filter -Name $Name -Id $Id -Moniker $Moniker -Tag $Tag -Command $Command -Source $Source
    166 
    167         if($Result.count -eq 1) {
    168             & "WinGet" $WingetArgs
    169             $Result = ""
    170         }
    171         elseif($Result.count -lt 1){
    172             Write-Host "Unable to locate package for installation"
    173             $Result = ""
    174         }
    175         else {
    176             Write-Host "Multiple packages found matching input criteria. Please refine the input."
    177         }
    178     }
    179     END
    180     {
    181         return $Result
    182     }
    183 }
    184 
    185 Export-ModuleMember -Function Install-WinGetPackage