-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathUninstall-ChocolateyPackage.ps1
More file actions
268 lines (213 loc) · 8.83 KB
/
Uninstall-ChocolateyPackage.ps1
File metadata and controls
268 lines (213 loc) · 8.83 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<#
.SYNOPSIS
Uninstalls a Chocolatey package or a list of packages.
.DESCRIPTION
Once the Chocolatey Software has been installed (see Install-ChocolateySoftware) this command
allows you to uninstall Software installed by Chocolatey,
or synced from Add-remove program (Business edition).
.PARAMETER Name
Package Name to uninstall, either from a configured source, a specified one such as a folder,
or the current directory '.'
.PARAMETER Version
Version - A specific version to install.
.PARAMETER Source
Source - The source to find the package(s) to install. Special sources
include: ruby, webpi, cygwin, windowsfeatures, and python. To specify
more than one source, pass it with a semi-colon separating the values (-
e.g. "'source1;source2'"). Defaults to default feeds.
.PARAMETER Credential
Credential used with authenticated feeds. Defaults to empty.
.PARAMETER Force
Force - force the behavior. Do not use force during normal operation -
it subverts some of the smart behavior for commands.
.PARAMETER CacheLocation
CacheLocation - Location for download cache, defaults to %TEMP% or value
in chocolatey.config file.
.PARAMETER NoProgress
Do Not Show Progress - Do not show download progress percentages.
Available in 0.10.4+.
.PARAMETER AcceptLicense
AcceptLicense - Accept license dialogs automatically. Reserved for future use.
.PARAMETER Timeout
CommandExecutionTimeout (in seconds) - The time to allow a command to
finish before timing out. Overrides the default execution timeout in the
configuration of 2700 seconds. '0' for infinite starting in 0.10.4.
.PARAMETER UninstallArguments
UninstallArguments - Uninstall Arguments to pass to the native installer
in the package. Defaults to unspecified.
.PARAMETER OverrideArguments
OverrideArguments - Should uninstall arguments be used exclusively
without appending to current package passed arguments? Defaults to false.
.PARAMETER NotSilent
NotSilent - Do not uninstall this silently. Defaults to false.
.PARAMETER ApplyArgsToDependencies
Apply Install Arguments To Dependencies - Should install arguments be
applied to dependent packages? Defaults to false.
.PARAMETER IgnoreDependencies
IgnoreDependencies - Ignore dependencies when installing package(s).
Defaults to false.
.PARAMETER ForceDependencies
RemoveDependencies - Uninstall dependencies when uninstalling package(s).
Defaults to false.
.PARAMETER SkipPowerShell
Skip Powershell - Do not run chocolateyUninstall.ps1. Defaults to false.
.PARAMETER ignorePackageCodes
IgnorePackageExitCodes - Exit with a 0 for success and 1 for non-succes-s,
no matter what package scripts provide for exit codes. Overrides the
default feature 'usePackageExitCodes' set to 'True'. Available in 0.9.10+.
.PARAMETER UsePackageCodes
UsePackageExitCodes - Package scripts can provide exit codes. Use those
for choco's exit code when non-zero (this value can come from a
dependency package). Chocolatey defines valid exit codes as 0, 1605,
1614, 1641, 3010. Overrides the default feature 'usePackageExitCodes'
set to 'True'.
Available in 0.9.10+.
.PARAMETER StopOnFirstFailure
Stop On First Package Failure - stop running install, upgrade or
uninstall on first package failure instead of continuing with others.
Overrides the default feature 'stopOnFirstPackageFailure' set to 'False'.
Available in 0.10.4+.
.PARAMETER AutoUninstaller
UseAutoUninstaller - Use auto uninstaller service when uninstalling.
Overrides the default feature 'autoUninstaller' set to 'True'.
Available in 0.9.10+.
.PARAMETER SkipAutoUninstaller
SkipAutoUninstaller - Skip auto uninstaller service when uninstalling.
Overrides the default feature 'autoUninstaller' set to 'True'. Available
in 0.9.10+.
.PARAMETER FailOnAutouninstaller
FailOnAutoUninstaller - Fail the package uninstall if the auto
uninstaller reports and error. Overrides the default feature
'failOnAutoUninstaller' set to 'False'. Available in 0.9.10+.
.PARAMETER IgnoreAutoUninstallerFailure
Ignore Auto Uninstaller Failure - Do not fail the package if auto
uninstaller reports an error. Overrides the default feature
'failOnAutoUninstaller' set to 'False'. Available in 0.9.10+.
.PARAMETER RunNonElevated
Throws if the process is not running elevated. use -RunNonElevated if you really want to run
even if the current shell is not elevated.
.EXAMPLE
Uninstall-ChocolateyPackage -Name Putty
.NOTES
https://github.com/chocolatey/choco/wiki/Commandsuninstall
#>
function Uninstall-ChocolateyPackage
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '')]
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = 'High'
)]
param
(
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[System.String[]]
$Name,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$Version,
[Parameter(ValueFromPipelineByPropertyName = $true)]
$Source,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[pscredential]
$Credential,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Switch]
$Force,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[System.String]
$CacheLocation,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Switch]
$NoProgress,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Switch]
$AcceptLicense,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[int]
$Timeout,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[System.String]
$UninstallArguments,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Switch]
$OverrideArguments,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Switch]
$NotSilent,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Switch]
$ApplyArgsToDependencies,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Switch]
$IgnoreDependencies,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Switch]
$ForceDependencies,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Switch]
$SkipPowerShell,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Switch]
$ignorePackageCodes,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Switch]
$UsePackageCodes,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Switch]
$StopOnFirstFailure,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Switch]
$AutoUninstaller,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Switch]
$SkipAutoUninstaller,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Switch]
$FailOnAutouninstaller,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Switch]
$IgnoreAutoUninstallerFailure,
[Parameter(DontShow)]
[switch]
$RunNonElevated = $(Assert-ChocolateyIsElevated)
)
begin
{
# Validate choco is installed or die. Will load the exe path from module cache.
# Should you want to specify an installation directory,
# you have to call Get-ChocolateyCommand -InstallDir <path> -Force to set the cache.
$chocoCmd = Get-ChocolateyCommand
# Removing the cache because it will be obsolete when uninstalling packages
Remove-ChocolateyPackageCache
}
process
{
if ($PSBoundParameters.ContainsKey('Name'))
{
$null = $PSBoundParameters.Remove('Name')
}
foreach ($PackageName in $Name)
{
$ChocoArguments = @('uninstall', $PackageName)
$ChocoArguments += @(Get-ChocolateyDefaultArgument @PSBoundParameters)
if ($PSCmdlet.ShouldProcess($PackageName, "Uninstall"))
{
#Impact confirmed, go choco go!
$ChocoArguments += @('-y')
Write-Debug -Message ('{0} {1}' -f $chocoCmd, $($ChocoArguments -join ' '))
&$chocoCmd $ChocoArguments | Foreach-Object -Process {
if ($_ -match '^You are uninstalling .* which is likely|\*\.install/\*\.portable|represents discoverability')
{
Write-Warning -Message ('{0}' -f $_)
}
else
{
Write-Verbose -Message ('{0}' -f $_)
}
}
}
}
}
}