-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwipe-mega-leftovers.ps1
More file actions
210 lines (180 loc) · 7.98 KB
/
wipe-mega-leftovers.ps1
File metadata and controls
210 lines (180 loc) · 7.98 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
<#
.SYNOPSIS
Removes MEGA Sync leftover folders from Windows Explorer by cleaning registry entries.
.DESCRIPTION
This script identifies and removes registry entries related to MEGA Sync that create
phantom folders in Windows Explorer. It targets specific registry locations known
to store shell namespace extensions to avoid lengthy full-system scans.
.PARAMETER WhatIf
Shows what would be removed without actually removing it.
.PARAMETER Confirm
Prompts for confirmation before removing registry entries.
.EXAMPLE
.\wipeMegaLeftovers.ps1
.EXAMPLE
.\wipeMegaLeftovers.ps1 -WhatIf
.EXAMPLE
.\wipeMegaLeftovers.ps1 -Confirm:$false
#>
[CmdletBinding(SupportsShouldProcess = $true)]
param()
# Define the registry locations where MEGA Sync typically stores its namespace extension entries
$registryPaths = @(
"HKCU:\Software\Classes\CLSID",
"HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace",
"HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace",
"HKLM:\Software\Classes\CLSID",
"HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace",
"HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace",
"HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel",
"HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel"
)
Write-Host "Scanning for MEGA Sync registry entries..." -ForegroundColor Yellow
$megaEntries = @()
$foundCount = 0
foreach ($path in $registryPaths) {
Write-Verbose "Scanning: $path"
# Check if the registry path exists
if (Test-Path $path) {
try {
# Get subkeys that might contain MEGA entries
$subKeys = Get-ChildItem -Path $path -ErrorAction SilentlyContinue
foreach ($subKey in $subKeys) {
# Check if the subkey name or value contains "MEGA"
if ($subKey.Name -match "MEGA") {
# Get the default value of the subkey to see if it contains MEGA
$defaultValue = $null
try {
$defaultValue = (Get-ItemProperty -Path $subKey.PSPath -ErrorAction SilentlyContinue)."(default)"
} catch {
# If default value access fails, continue to next
continue
}
if ($defaultValue -and $defaultValue -match "MEGA") {
$megaEntries += [PSCustomObject]@{
Path = $subKey.PSPath
Name = $subKey.Name.Split('\')[-1]
Value = $defaultValue
Location = $path
}
$foundCount++
}
} else {
# Even if the key name doesn't match, check its default value
$defaultValue = $null
try {
$defaultValue = (Get-ItemProperty -Path $subKey.PSPath -ErrorAction SilentlyContinue)."(default)"
} catch {
continue
}
if ($defaultValue -and $defaultValue -match "MEGA") {
$megaEntries += [PSCustomObject]@{
Path = $subKey.PSPath
Name = $subKey.Name.Split('\')[-1]
Value = $defaultValue
Location = $path
}
$foundCount++
}
}
}
} catch {
Write-Warning "Could not access $path : $($_.Exception.Message)"
}
}
}
# Also check for MEGA entries in the Shell Extensions
$shellExtPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved"
if (Test-Path $shellExtPath) {
try {
$shellExtItems = Get-ChildItem -Path $shellExtPath -ErrorAction SilentlyContinue
foreach ($item in $shellExtItems) {
$itemValue = $null
try {
$itemValue = (Get-ItemProperty -Path $item.PSPath -ErrorAction SilentlyContinue)."(default)"
} catch {
continue
}
if ($itemValue -and $itemValue -match "MEGA") {
$megaEntries += [PSCustomObject]@{
Path = $item.PSPath
Name = $item.Name.Split('\')[-1]
Value = $itemValue
Location = $shellExtPath
}
$foundCount++
}
}
} catch {
Write-Warning "Could not access $shellExtPath : $($_.Exception.Message)"
}
}
if ($megaEntries.Count -eq 0) {
Write-Host "No MEGA Sync registry entries found." -ForegroundColor Green
Write-Host "Checking for MEGA folders in common locations..." -ForegroundColor Yellow
# Check for MEGA folders in common locations
$commonLocations = @(
"$env:USERPROFILE\Desktop",
"$env:USERPROFILE\Documents",
"$env:USERPROFILE\OneDrive\Desktop",
"$env:PUBLIC\Desktop"
)
$megaFolders = @()
foreach ($location in $commonLocations) {
if (Test-Path $location) {
$folders = Get-ChildItem -Path $location -Directory -ErrorAction SilentlyContinue | Where-Object { $_.Name -like "MEGA_*" }
$megaFolders += $folders
}
}
if ($megaFolders.Count -gt 0) {
Write-Host "Found $($megaFolders.Count) MEGA-related folders:" -ForegroundColor Yellow
foreach ($folder in $megaFolders) {
Write-Host " - $($folder.FullName)" -ForegroundColor Cyan
}
$removeFolders = $PSCmdlet.ShouldProcess("MEGA folders", "Remove")
if ($removeFolders) {
foreach ($folder in $megaFolders) {
try {
Remove-Item -Path $folder.FullName -Recurse -Force -ErrorAction Stop
Write-Host "Removed folder: $($folder.FullName)" -ForegroundColor Green
} catch {
Write-Warning "Could not remove folder $($folder.FullName): $($_.Exception.Message)"
}
}
}
} else {
Write-Host "No MEGA folders found in common locations." -ForegroundColor Green
}
return
}
Write-Host "Found $foundCount MEGA Sync registry entries:" -ForegroundColor Yellow
foreach ($entry in $megaEntries) {
Write-Host " Registry Key: $($entry.Path)" -ForegroundColor Cyan
Write-Host " Default Value: $($entry.Value)" -ForegroundColor Gray
Write-Host " Location: $($entry.Location)" -ForegroundColor DarkGray
Write-Host ""
}
# Confirm removal
if ($megaEntries.Count -gt 0) {
$removeEntries = $PSCmdlet.ShouldProcess("MEGA registry entries", "Remove")
if ($removeEntries) {
Write-Host "Removing MEGA Sync registry entries..." -ForegroundColor Yellow
$removedCount = 0
foreach ($entry in $megaEntries) {
try {
Remove-Item -Path $entry.Path -Recurse -Force -ErrorAction Stop
Write-Host "Successfully removed: $($entry.Path)" -ForegroundColor Green
$removedCount++
} catch {
Write-Warning "Failed to remove $($entry.Path): $($_.Exception.Message)"
}
}
Write-Host "Successfully removed $removedCount registry entries." -ForegroundColor Green
# Suggest restarting Explorer to apply changes
Write-Host "To see changes in Windows Explorer, you may need to:" -ForegroundColor Yellow
Write-Host "1. Restart Windows Explorer (Task Manager -> Details tab -> right-click explorer.exe -> Restart)" -ForegroundColor White
Write-Host "2. Or restart your computer." -ForegroundColor White
}
} else {
Write-Host "No changes were made to the registry." -ForegroundColor Green
}