This repository was archived by the owner on Jun 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathUninstall-PSResource.ps1
More file actions
76 lines (67 loc) · 2.75 KB
/
Uninstall-PSResource.ps1
File metadata and controls
76 lines (67 loc) · 2.75 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
function Uninstall-PSResource {
[OutputType([void])]
[cmdletbinding(SupportsShouldProcess = $true)]
Param
(
# Specifies an array of resource names to uninstall.
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true,
Position = 0,
ParameterSetName = 'NameParameterSet')]
[ValidateNotNullOrEmpty()]
[String[]]
$Name,
# Accepts a PSRepositoryItemInfo object.
# For example, output Get-InstalledModule to a variable and use that variable as the InputObject argument.
[Parameter(Mandatory = $true,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true,
Position = 0,
ParameterSetName = 'InputObject')]
[ValidateNotNull()]
[PSCustomObject[]]
$InputObject,
# Specifies the minimum version of the resource to uninstall (can't be used with the RequiredVersion or AllVersions parameter).
[Parameter(ValueFromPipelineByPropertyName = $true,
ParameterSetName = 'NameParameterSet')]
[ValidateNotNull()]
[string]
$MinimumVersion,
# Specifies the exact version number of the reource to uninstall (can't be used with the MinimumVersion, MaximumVersion, or AllVersions parameter).
[Parameter(ValueFromPipelineByPropertyName = $true,
ParameterSetName = 'NameParameterSet')]
[ValidateNotNull()]
[string]
$RequiredVersion,
# Specifies the maximum, or newest, version of the resource to uninstall (can't be used with the RequiredVersion or AllVersions parameter).
[Parameter(ValueFromPipelineByPropertyName = $true,
ParameterSetName = 'NameParameterSet')]
[ValidateNotNull()]
[string]
$MaximumVersion,
# Specifies that you want to include all available versions of a module (can't be used with the MinimumVersion, MaximumVersion, or RequiredVersion parameter).
[Parameter(ParameterSetName = 'NameParameterSet')]
[switch]
$AllVersions,
# Uninstalls a resource without asking for user confirmation.
[Parameter()]
[Switch]
$Force,
# Allows a prerelease version to be uninstalled.
[Parameter(ParameterSetName = 'NameParameterSet')]
[switch]
$Prerelease
)
begin { }
process {
foreach ($n in $Name) {
if ($pscmdlet.ShouldProcess($n)) {
if (Get-PSResource $n) {
# Uninstall the resource
Write-Verbose -message "Successfully uninstalled $n"
}
}
}
}
end { }
}