-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebEx_Scrub.ps1
More file actions
145 lines (125 loc) · 4.83 KB
/
Copy pathWebEx_Scrub.ps1
File metadata and controls
145 lines (125 loc) · 4.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
<#
.SYNOPSIS
Cleans up leftover Webex and Cisco Spark files, shortcuts, and registry keys for all user profiles.
#>
#region Configuration
$UserProfilesRoot = 'C:\Users'
# Data folders to remove under each profile
$RelativeDataPaths = @(
'AppData\Local\Webex',
'AppData\Roaming\Webex',
'AppData\Local\Cisco\Spark',
'AppData\Roaming\Cisco Spark'
)
# 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 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')
# Load hive
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"
}
}
# Unload hive
reg.exe unload "HKU\$hiveName" 2>$null
}
# 1) Remove machine‑wide registry keys
Write-Host "`n=== Removing machine‑wide registry entries ==="
Remove-MachineRegKeys
# 2) 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)"
}
}
# 3) Clean Public shortcuts only
Write-Host "`n=== Cleaning Public shortcuts ==="
Remove-Shortcuts -BaseFolder $PublicDesktop -Patterns $ShortcutPatterns
Remove-Shortcuts -BaseFolder $PublicStartMenu -Patterns $ShortcutPatterns