winget-cli

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

Uninstall-WinGetPackage.ps1 (5436B)


      1 Function Uninstall-WinGetPackage{
      2     <#
      3         .SYNOPSIS
      4         Uninstalls a package from the local system. 
      5         Additional options can be provided to filter the output, much like the search command.
      6         
      7         .DESCRIPTION
      8         By running this cmdlet with the required inputs, it will uninstall a package installed on the local system.
      9 
     10         .PARAMETER Filter
     11         Used to search across multiple fields of the package.
     12         
     13         .PARAMETER Id
     14         Used to specify the Id of the package
     15 
     16         .PARAMETER Name
     17         Used to specify the Name of the package
     18 
     19         .PARAMETER Moniker
     20         Used to specify the Moniker of the package
     21 
     22         .PARAMETER Version
     23         Used to specify the Version of the package
     24         
     25         .PARAMETER Exact
     26         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.
     27 
     28         .PARAMETER Source
     29         Name of the Windows Package Manager private source. Can be identified by running: "Get-WinGetSource" and using the source Name
     30 
     31         .PARAMETER Interactive
     32         Used to specify the uninstaller should be run in interactive mode.
     33 
     34         .PARAMETER Silent
     35         Used to specify the uninstaller should be run in silent mode with no user input.
     36 
     37         .PARAMETER Log
     38         Used to specify the location for the log location if it is supported by the package uninstaller.
     39 
     40         .PARAMETER VerboseLog
     41         Used to provide verbose logging for the Windows Package Manager.
     42 
     43         .PARAMETER Header
     44         Used to specify the value to pass as the "Windows-Package-Manager" HTTP header for a REST source.
     45         
     46         .PARAMETER AcceptSourceAgreement
     47         Used to explicitly accept any agreement required by the source.
     48 
     49         .PARAMETER Local
     50         Used to uninstall from a local manifest
     51 
     52         .EXAMPLE
     53         Uninstall-WinGetPackage -id "Publisher.Package"
     54 
     55         This example expects only a single configured REST source with a package containing "Publisher.Package" as a valid identifier.
     56 
     57         .EXAMPLE
     58         Uninstall-WinGetPackage -id "Publisher.Package" -source "Private"
     59 
     60         This example expects the REST source named "Private" with a package containing "Publisher.Package" as a valid identifier.
     61 
     62         .EXAMPLE
     63         Uninstall-WinGetPackage -Name "Package"
     64 
     65         This example expects a configured source contains a package with "Package" as a valid name.
     66     #>
     67 
     68     PARAM(
     69         [Parameter(Position=0)] $Filter,
     70         [Parameter()]           $Name,
     71         [Parameter()]           $Id,
     72         [Parameter()]           $Moniker,
     73         [Parameter()]           $Source,
     74         [Parameter()] [switch]  $Interactive,
     75         [Parameter()] [switch]  $Silent,
     76         [Parameter()] [string]  $Version,
     77         [Parameter()] [switch]  $Exact,
     78         [Parameter()] [switch]  $Override,
     79         [Parameter()] [System.IO.FileInfo]  $Location,
     80         [Parameter()] [switch]  $Force,
     81         [Parameter()] [System.IO.FileInfo]  $Log, ## This is a path of where to create a log.
     82         [Parameter()] [switch]  $AcceptSourceAgreements,
     83         [Parameter()] [switch]  $Local # This is for installing local manifests
     84     )
     85     BEGIN
     86     {
     87         [string[]] $WinGetArgs  = "Uninstall"
     88         IF($PSBoundParameters.ContainsKey('Filter')){
     89             IF($Local) {
     90                 $WinGetArgs += "--Manifest"
     91             }
     92             $WinGetArgs += $Filter
     93         }
     94         IF($PSBoundParameters.ContainsKey('Name')){
     95             $WinGetArgs += "--Name", $Name
     96         }
     97         IF($PSBoundParameters.ContainsKey('Id')){
     98             $WinGetArgs += "--Id", $Id
     99         }
    100         IF($PSBoundParameters.ContainsKey('Moniker')){
    101             $WinGetArgs += "--Moniker", $Moniker
    102         }
    103         IF($PSBoundParameters.ContainsKey('Source')){
    104             $WinGetArgs += "--Source", $Source
    105         }
    106         IF($Interactive){
    107             $WinGetArgs += "--Interactive"
    108         }
    109         IF($Silent){
    110             $WinGetArgs += "--Silent"
    111         }
    112         if($PSBoundParameters.ContainsKey('Version')){
    113             $WinGetArgs += "--Version", $Version
    114         }
    115         if($Exact){
    116             $WinGetArgs += "--Exact"
    117         }
    118         if($PSBoundParameters.ContainsKey('Log')){
    119             $WinGetArgs += "--Log", $Log
    120         }
    121         if($PSBoundParameters.ContainsKey('Location')){
    122             $WinGetArgs += "--Location", $Location
    123         }
    124         if($Force){
    125             $WinGetArgs += "--Force"
    126         }
    127     }
    128     PROCESS
    129     {
    130         ## Exact, ID and Source - Talk with tomorrow to better understand this.
    131         IF(!$Local) {
    132             $Result = Find-WinGetPackage -Filter $Filter -Name $Name -Id $Id -Moniker $Moniker -Tag $Tag -Command $Command -Source $Source
    133         }
    134 
    135         if($Result.count -eq 1 -or $Local) {
    136             & "WinGet" $WingetArgs
    137             $Result = ""
    138         }
    139         elseif($Result.count -lt 1){
    140             Write-Host "Unable to locate package for uninstallation"
    141             $Result = ""
    142         }
    143         else {
    144             Write-Host "Multiple packages found matching input criteria. Please refine the input."
    145         }
    146     }
    147     END
    148     {
    149         return $Result
    150     }
    151 }
    152 
    153 New-Alias -Name Remove-WinGetPackage -Value Uninstall-WinGetPackage
    154 
    155 Export-ModuleMember -Function Uninstall-WinGetPackage
    156 Export-ModuleMember -Alias Remove-WinGetPackage