|
| 1 | +# Ensure admin permissions |
1 | 2 | if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { |
2 | | - Write-Warning "couldnt run because you didnt run as admin." |
| 3 | + Write-Warning "run this script as an admin!" |
3 | 4 | Exit |
4 | 5 | } |
5 | 6 |
|
6 | | -Write-Host "starting ms edge removal, this could take a while..." -ForegroundColor Cyan |
| 7 | +Write-Host "starting ms edge removal, this could take a while..." |
7 | 8 |
|
8 | | -Write-Host "closing ms edge processes..." -ForegroundColor Yellow |
| 9 | +Write-Host "closing ms edge processes..." |
9 | 10 | Stop-Process -Name "msedge" -Force -ErrorAction SilentlyContinue |
10 | 11 |
|
11 | | -Write-Host "running forced uninstallation switch..." -ForegroundColor Yellow |
12 | | -$edgeDir = "C:\Program Files (x86)\Microsoft\Edge\Application" |
13 | | -if (Test-Path $edgeDir) { |
14 | | - $installerPath = Get-ChildItem -Path $edgeDir -Filter "setup.exe" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 |
15 | | - if ($installerPath) { |
16 | | - $installerDir = Split-Path $installerPath.FullName |
17 | | - Start-Process -FilePath "$installerDir\setup.exe" -ArgumentList "--uninstall --system-level --verbose-logging --force-uninstall" -Wait -NoNewWindow |
18 | | - Write-Host "core edge application files uninstalled successfully." -ForegroundColor Green |
19 | | - } else { |
20 | | - Write-Host "edge setup.exe not found. (you might have removed edge already.) proceeding with registry and folder cleanup." -ForegroundColor Gray |
| 12 | +Write-Host "running forced uninstallation switch..." |
| 13 | +$edgeFolder = Get-ChildItem -Path "$env:ProgramFiles(x86)\Microsoft\Edge\Application" -Filter "1*" -Directory -ErrorAction SilentlyContinue | Select-Object -First 1 |
| 14 | +if ($edgeFolder) { |
| 15 | + $setupExe = Join-Path $edgeFolder.FullName "Installer\setup.exe" |
| 16 | + if (Test-Path $setupExe) { |
| 17 | + Start-Process -FilePath $setupExe -ArgumentList "--uninstall --system-level --verbose-logging --force-uninstall" -Wait -NoNewWindow |
21 | 18 | } |
22 | 19 | } |
23 | 20 |
|
24 | 21 | Write-Host "unregistering modern application package hooks..." |
25 | | -# Filter out system-protected items like DevToolsClient before feeding them to Remove-AppxPackage |
| 22 | +# Safely filter packages before passing them to the removal engine |
26 | 23 | Get-AppxPackage -AllUsers *MicrosoftEdge* | Where-Object { $_.NonRemovable -ne $true -and $_.PackageFullName -notlike "*DevTools*" } | ForEach-Object { |
27 | 24 | try { |
28 | 25 | Remove-AppxPackage -AllUsers -Package $_.PackageFullName -ErrorAction SilentlyContinue |
29 | 26 | } catch { |
30 | | - # Silent fail for locked components |
| 27 | + # Catch-all to keep the output completely clean |
31 | 28 | } |
32 | 29 | } |
33 | 30 |
|
34 | | -Write-Host "purging edge local cache, profile data, and leftovers..." -ForegroundColor Yellow |
35 | | -$localEdgePath = "$env:LocalAppData\Microsoft\Edge" |
36 | | -if (Test-Path $localEdgePath) { |
37 | | - Remove-Item -Path $localEdgePath -Recurse -Force -ErrorAction SilentlyContinue |
38 | | - Write-Host "edge local cache removed." -ForegroundColor Green |
39 | | -} |
| 31 | +# Also handle provisioned deployment items silently |
| 32 | +Get-AppxProvisionedPackage -Online | Where-Object { $_.PackageName -like "*MicrosoftEdge*" } | Remove-AppxProvisionedPackage -Online -ErrorAction SilentlyContinue |
40 | 33 |
|
41 | | -$progEdgePath = "C:\Program Files (x86)\Microsoft\Edge" |
42 | | -$progEdgeUpdatePath = "C:\Program Files (x86)\Microsoft\EdgeUpdate" |
| 34 | +Write-Host "purging edge local cache, profile data, and leftovers..." |
| 35 | +Remove-Item -Path "$env:LocalAppData\Microsoft\Edge" -Recurse -Force -ErrorAction SilentlyContinue |
| 36 | +Remove-Item -Path "$env:ProgramFiles(x86)\Microsoft\Edge" -Recurse -Force -ErrorAction SilentlyContinue |
| 37 | +Remove-Item -Path "$env:ProgramFiles(x86)\Microsoft\EdgeUpdate" -Recurse -Force -ErrorAction SilentlyContinue |
| 38 | +Write-Host "program files residues removed." |
43 | 39 |
|
44 | | -if (Test-Path $progEdgePath) { |
45 | | - Remove-Item -Path $progEdgePath -Recurse -Force -ErrorAction SilentlyContinue |
46 | | -} |
47 | | -if (Test-Path $progEdgeUpdatePath) { |
48 | | - Remove-Item -Path $progEdgeUpdatePath -Recurse -Force -ErrorAction SilentlyContinue |
49 | | -} |
50 | | -Write-Host "program files residues removed." -ForegroundColor Green |
51 | | - |
52 | | -Write-Host "erasing ghost registry listings from settings..." -ForegroundColor Yellow |
| 40 | +Write-Host "erasing ghost registry listings from settings..." |
53 | 41 | $regPaths = @( |
54 | 42 | "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Edge", |
55 | 43 | "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Edge" |
56 | 44 | ) |
57 | | - |
58 | | -foreach ($regPath in $regPaths) { |
59 | | - if (Test-Path $regPath) { |
60 | | - Remove-Item -Path $regPath -Recurse -Force -ErrorAction SilentlyContinue |
61 | | - Write-Host "ghost registry entries cleared from: $regPath" -ForegroundColor Green |
| 45 | +foreach ($path in $regPaths) { |
| 46 | + if (Test-Path $path) { |
| 47 | + Remove-Item -Path $path -Recurse -Force -ErrorAction SilentlyContinue |
62 | 48 | } |
63 | 49 | } |
64 | 50 |
|
65 | | -Write-Host "congratulations, the removal was a success!" -ForegroundColor Green |
66 | | -Write-Host "a system reboot is recommended to refresh the windows settings cache, but you can do that at any time." -ForegroundColor Cyan |
| 51 | +Write-Host "congratulations, the removal was a success!" |
| 52 | +Write-Host "a system reboot is recommended to refresh the windows settings cache, but you can do that at any time." |
0 commit comments