1+ # Ensure admin permissions
2+ if (-not ([Security.Principal.WindowsPrincipal ][Security.Principal.WindowsIdentity ]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole ]::Administrator)) {
3+ Write-Warning " run this script as an admin!"
4+ Exit
5+ }
6+
7+ Write-Host " starting ms edge removal..."
8+
9+ Write-Host " closing ms edge processes..."
10+ Stop-Process - Name " msedge" - Force - ErrorAction SilentlyContinue
11+
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
18+ }
19+ }
20+
21+ Write-Host " unregistering modern application package hooks... (thisll take a while)"
22+ # Safely filter packages before passing them to the removal engine
23+ Get-AppxPackage - AllUsers * MicrosoftEdge* | Where-Object { $_.NonRemovable -ne $true -and $_.PackageFullName -notlike " *DevTools*" } | ForEach-Object {
24+ try {
25+ Remove-AppxPackage - AllUsers - Package $_.PackageFullName - ErrorAction SilentlyContinue
26+ } catch {
27+ # Catch-all to keep the output completely clean
28+ }
29+ }
30+
31+ # Also handle provisioned deployment items silently
32+ Get-AppxProvisionedPackage - Online | Where-Object { $_.PackageName -like " *MicrosoftEdge*" } | Remove-AppxProvisionedPackage - Online - ErrorAction SilentlyContinue
33+
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."
39+
40+ Write-Host " erasing ghost registry listings from settings..."
41+ $regPaths = @ (
42+ " HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Edge" ,
43+ " HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Edge"
44+ )
45+ foreach ($path in $regPaths ) {
46+ if (Test-Path $path ) {
47+ Remove-Item - Path $path - Recurse - Force - ErrorAction SilentlyContinue
48+ }
49+ }
50+
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