-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWebEx_Scrub.ps1
189 lines (163 loc) · 6.41 KB
/
WebEx_Scrub.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
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
<#
.SYNOPSIS
Cleans up leftover Webex and Cisco Spark files, shortcuts, registry keys, and uninstalls MSI packages for all user profiles.
#>
#region Configuration
$UserProfilesRoot = 'C:\Users'
# MSI product name patterns to uninstall
$MsiNamePatterns = @('*Webex*', '*Cisco Spark*')
# Data folders to remove under each profile
$RelativeDataPaths = @(
'AppData\Local\Webex',
'AppData\Roaming\Webex',
'AppData\Local\Cisco\Spark',
'AppData\Roaming\Cisco Spark',
'AppData\Local\Programs\Cisco Spark\',
'AppData\Local\CiscoSpark',
'AppData\Local\CiscoSparkLauncher',
'C:\Program Files\Cisco Spark\',
'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Webex'
)
# Shortcut filename patterns
$ShortcutPatterns = @('*Webex*.lnk', '*Cisco Spark*.lnk')
# Machine‑wide registry keys to delete
$MachineRegKeys = @(
'HKLM:\SOFTWARE\Cisco\Webex',
'HKLM:\SOFTWARE\Webex',
'HKLM:\SOFTWARE\Wow6432Node\Cisco\Webex',
'HKLM:\SOFTWARE\Wow6432Node\Webex',
'HKLM:\SOFTWARE\Cisco\Spark',
'HKLM:\SOFTWARE\Cisco Spark',
'HKLM:\SOFTWARE\Wow6432Node\Cisco\Spark',
'HKLM:\SOFTWARE\Wow6432Node\Cisco Spark',
'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Cisco Webex',
'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Cisco Webex',
'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Cisco Spark',
'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Cisco Spark'
)
# Per‑user registry subkeys under HKCU to delete
$UserRegSubKeys = @(
'Software\Cisco\Webex',
'Software\Webex',
'Software\Cisco\Spark',
'Software\Cisco Spark'
)
# Public shortcuts locations
$PublicDesktop = Join-Path $UserProfilesRoot 'Public\Desktop'
$PublicStartMenu = Join-Path $Env:ProgramData 'Microsoft\Windows\Start Menu\Programs'
#endregion
function Uninstall-MSIProducts {
Write-Host "`n=== Uninstalling MSI‑based Webex/Spark products ==="
# Use Get-WmiObject Win32_Product to find installed MSI products
$installed = Get-WmiObject -Class Win32_Product -ErrorAction SilentlyContinue |
Where-Object {
foreach ($pattern in $MsiNamePatterns) {
if ($_.Name -like $pattern) { return $true }
}
return $false
}
if (-not $installed) {
Write-Host "ℹ No MSI products matching Webex/Spark found."
return
}
foreach ($pkg in $installed) {
Write-Host "→ Uninstalling: $($pkg.Name) (ProductCode: $($pkg.IdentifyingNumber))"
try {
$exit = $pkg.Uninstall()
if ($exit.ReturnValue -eq 0) {
Write-Host "✔ Successfully uninstalled $($pkg.Name)"
}
else {
Write-Warning "⚠ Failed to uninstall $($pkg.Name) (ReturnValue: $($exit.ReturnValue))"
}
}
catch {
Write-Warning "⚠ Exception uninstalling $($pkg.Name): $_"
}
}
}
function Remove-Paths {
param([string[]] $Paths)
foreach ($p in $Paths) {
if (Test-Path $p) {
Remove-Item -LiteralPath $p -Recurse -Force -ErrorAction SilentlyContinue
Write-Host "✔ Removed: $p"
}
else {
Write-Host "ℹ Not found: $p"
}
}
}
function Remove-Shortcuts {
param([string] $BaseFolder, [string[]] $Patterns)
foreach ($pattern in $Patterns) {
$matches = Get-ChildItem -Path $BaseFolder -Filter $pattern -Recurse -ErrorAction SilentlyContinue
if ($matches) {
foreach ($lnk in $matches) {
Remove-Item -LiteralPath $lnk.FullName -Force -ErrorAction SilentlyContinue
Write-Host "✔ Removed shortcut: $($lnk.FullName)"
}
}
else {
Write-Host "ℹ No shortcuts matching '$pattern' in $BaseFolder"
}
}
}
function Remove-MachineRegKeys {
foreach ($key in $MachineRegKeys) {
if (Test-Path $key) {
Remove-Item -Path $key -Recurse -Force -ErrorAction SilentlyContinue
Write-Host "✔ Removed registry key: $key"
}
else {
Write-Host "ℹ Registry key not found: $key"
}
}
}
function Remove-UserRegKeys {
param([string] $NtUserDatPath)
$hiveName = 'TempHive_' + [Guid]::NewGuid().ToString('N')
reg.exe load "HKU\$hiveName" "$NtUserDatPath" 2>$null
foreach ($subKey in $UserRegSubKeys) {
$fullKey = "Registry::HKEY_USERS\$hiveName\$subKey"
if (Test-Path $fullKey) {
Remove-Item -Path $fullKey -Recurse -Force -ErrorAction SilentlyContinue
Write-Host "✔ Removed user-registry: HKU:\$hiveName\$subKey"
}
else {
Write-Host "ℹ User-registry not found: HKU:\$hiveName\$subKey"
}
}
reg.exe unload "HKU\$hiveName" 2>$null
}
# === MAIN ===
# 1) Uninstall any MSI‑based Webex/Spark products
Uninstall-MSIProducts
# 2) Remove machine‑wide registry keys
Write-Host "`n=== Removing machine‑wide registry entries ==="
Remove-MachineRegKeys
# 3) Process each real user profile
$skip = 'Default','Default User','Public','All Users'
$profiles = Get-ChildItem -Directory -Path $UserProfilesRoot |
Where-Object { $skip -notcontains $_.Name }
foreach ($prof in $profiles) {
Write-Host "`n=== Profile: $($prof.Name) ==="
# a) Delete AppData folders
$paths = $RelativeDataPaths | ForEach-Object { Join-Path $prof.FullName $_ }
Remove-Paths -Paths $paths
# b) Delete shortcuts
Remove-Shortcuts -BaseFolder (Join-Path $prof.FullName 'Desktop') -Patterns $ShortcutPatterns
Remove-Shortcuts -BaseFolder (Join-Path $prof.FullName 'AppData\Roaming\Microsoft\Windows\Start Menu\Programs') -Patterns $ShortcutPatterns
# c) Delete per-user registry
$ntuser = Join-Path $prof.FullName 'NTUSER.DAT'
if (Test-Path $ntuser) {
Remove-UserRegKeys -NtUserDatPath $ntuser
}
else {
Write-Warning "NTUSER.DAT not found for profile $($prof.Name)"
}
}
# 4) Clean Public shortcuts only
Write-Host "`n=== Cleaning Public shortcuts ==="
Remove-Shortcuts -BaseFolder $PublicDesktop -Patterns $ShortcutPatterns
Remove-Shortcuts -BaseFolder $PublicStartMenu -Patterns $ShortcutPatterns