-
Notifications
You must be signed in to change notification settings - Fork 11
/
Uninstall-CVModules.ps1
72 lines (62 loc) · 2.33 KB
/
Uninstall-CVModules.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
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
#
# Package uninstall script for 'CommvaultPSModule'
#
# Author: Gary Stoops
# Company: Commvault
#
Clear-Host
function UninstallModules {
begin {
try {
$InstalledModules = Get-InstalledModule -Name 'Commvault.*' -ErrorAction Stop
}
catch [System.Exception] {
if (-not ($_.CategoryInfo.Category -eq 'ObjectNotFound')) {
throw $_
}
else {
Write-Information -InformationAction Continue -MessageData "INFO: $($MyInvocation.MyCommand): Existing Commvault PowerShell module installation not found"
}
}
catch {
throw $_
}
}
process {
try {
if ($InstalledModules.Length -gt 0) {
$curModule = 0
$complete = [math]::Round($curModule/$InstalledModules.Length * 100)
Write-Progress -Activity "Uninstalling Commvault Modules" -Status "$complete% Complete:" -PercentComplete $complete;
foreach ($Module in $InstalledModules) {
if ($Module.Name.SubString(0, 10) -eq 'Commvault.') {
try { # uninstall module from local computer
Uninstall-Module -Name $Module.Name -ErrorAction Stop
}
catch [System.Exception] {
$errorId = 'AdminPrivilegesRequiredForUninstall'
if ($_.FullyQualifiedErrorId.SubString(0, $errorId.Length) -eq $errorId) {
Write-Warning -Message "$($MyInvocation.MyCommand): Please elevate current user execution policy or start PowerShell with Run as Administrator"
break
}
else {
throw $_
}
}
}
$curModule++
$complete = [math]::Round($curModule/$InstalledModules.Length * 100)
Write-Progress -Activity "Uninstalling Commvault modules" -Status "$complete% complete:" -PercentComplete $complete;
}
}
}
catch {
throw $_
}
}
end {
Start-Sleep -Seconds 3
}
}
####
UninstallModules