Add remove_ms_edge_and_ie_if_exist.ps1

This commit is contained in:
billy 2026-02-07 01:42:13 +02:00
parent 9abba755bf
commit f530426dbc
1 changed files with 108 additions and 0 deletions

View File

@ -0,0 +1,108 @@
# Script to remove Internet Explorer and Microsoft Edge
# Check if the script is running with administrator privileges
if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Warning "Please run this script as Administrator!"
Break
}
Write-Host "Starting removal of Internet Explorer and Microsoft Edge..." -ForegroundColor Cyan
# ===== Remove Internet Explorer =====
Write-Host "`nChecking for Internet Explorer..." -ForegroundColor Yellow
try {
# Check if Internet Explorer is installed as a Windows feature
$ieFeature = Get-WindowsOptionalFeature -Online | Where-Object { $_.FeatureName -eq "Internet-Explorer-Optional-amd64" }
if ($ieFeature -and $ieFeature.State -eq "Enabled") {
Write-Host "Disabling Internet Explorer..." -ForegroundColor Green
Disable-WindowsOptionalFeature -Online -FeatureName "Internet-Explorer-Optional-amd64" -NoRestart
Write-Host "Internet Explorer has been disabled!" -ForegroundColor Green
} else {
Write-Host "Internet Explorer is already disabled or not found." -ForegroundColor Gray
}
} catch {
Write-Host "Error removing Internet Explorer: $_" -ForegroundColor Red
}
# ===== Remove Microsoft Edge (Legacy) =====
Write-Host "`nChecking for Microsoft Edge Legacy..." -ForegroundColor Yellow
try {
$edgeLegacyPath = "$env:SystemRoot\SystemApps\Microsoft.MicrosoftEdge_8wekyb3d8bbwe"
if (Test-Path $edgeLegacyPath) {
Write-Host "Removing Microsoft Edge Legacy..." -ForegroundColor Green
# Take ownership and remove Edge Legacy
takeown /f $edgeLegacyPath /r /d y | Out-Null
icacls $edgeLegacyPath /grant administrators:F /t | Out-Null
Remove-Item -Path $edgeLegacyPath -Recurse -Force -ErrorAction SilentlyContinue
Write-Host "Microsoft Edge Legacy has been removed!" -ForegroundColor Green
} else {
Write-Host "Microsoft Edge Legacy not found." -ForegroundColor Gray
}
} catch {
Write-Host "Error removing Edge Legacy: $_" -ForegroundColor Red
}
# ===== Remove Microsoft Edge (Chromium-based) =====
Write-Host "`nChecking for Microsoft Edge (Chromium)..." -ForegroundColor Yellow
try {
# Find Edge installation path
$edgePaths = @(
"${env:ProgramFiles(x86)}\Microsoft\Edge\Application",
"$env:ProgramFiles\Microsoft\Edge\Application"
)
$edgeFound = $false
foreach ($edgePath in $edgePaths) {
if (Test-Path $edgePath) {
$edgeFound = $true
# Find the version folder
$versionFolders = Get-ChildItem -Path $edgePath -Directory | Where-Object { $_.Name -match '^\d+\.\d+\.\d+\.\d+$' }
if ($versionFolders) {
$latestVersion = $versionFolders | Sort-Object Name -Descending | Select-Object -First 1
$uninstallerPath = Join-Path $latestVersion.FullName "Installer\setup.exe"
if (Test-Path $uninstallerPath) {
Write-Host "Uninstalling Microsoft Edge..." -ForegroundColor Green
# Run Edge uninstaller with silent parameters
Start-Process -FilePath $uninstallerPath -ArgumentList "--uninstall --system-level --verbose-logging --force-uninstall" -Wait
Write-Host "Microsoft Edge has been uninstalled!" -ForegroundColor Green
} else {
Write-Host "Edge uninstaller not found at: $uninstallerPath" -ForegroundColor Yellow
}
}
}
}
if (-not $edgeFound) {
Write-Host "Microsoft Edge (Chromium) not found." -ForegroundColor Gray
}
} catch {
Write-Host "Error removing Microsoft Edge: $_" -ForegroundColor Red
}
# ===== Summary =====
Write-Host "`n========================================" -ForegroundColor Cyan
Write-Host "Removal process completed!" -ForegroundColor Cyan
Write-Host "A system restart is recommended." -ForegroundColor Yellow
Write-Host "========================================" -ForegroundColor Cyan
# Ask if user wants to restart now
$restart = Read-Host "`nDo you want to restart now? (Y/N)"
if ($restart -eq 'Y' -or $restart -eq 'y') {
Write-Host "Restarting in 10 seconds..." -ForegroundColor Yellow
Start-Sleep -Seconds 10
Restart-Computer -Force
}