From 7dd6b9c6864956ff1cf1e08d968faa708f4d2fac Mon Sep 17 00:00:00 2001 From: Taylor Christian Newsome <86472964+SleepTheGod@users.noreply.github.com> Date: Tue, 6 Aug 2024 06:21:42 -0400 Subject: [PATCH 1/3] Update edgeremoval.ps1 --- edgeremoval.ps1 | 344 +++++++++++++++++------------------------------- 1 file changed, 123 insertions(+), 221 deletions(-) diff --git a/edgeremoval.ps1 b/edgeremoval.ps1 index 5f3a7a3c39..9783defff6 100644 --- a/edgeremoval.ps1 +++ b/edgeremoval.ps1 @@ -1,253 +1,155 @@ -# Script Metadata -# Created by AveYo, source: https://raw.githubusercontent.com/AveYo/fox/main/Edge_Removal.bat -# Powershell Conversion and Refactor done by Chris Titus Tech +<# +.SYNOPSIS + This script removes Microsoft Edge and related components from the system. + +.DESCRIPTION + This script performs the following tasks: + - Terminates Edge-related processes. + - Removes registry entries associated with Microsoft Edge. + - Uninstalls Edge-related AppX packages. + - Cleans up shortcut files. + - Configures Edge policy settings to prevent reinstallation. + +.NOTES + Updated by Taylor Christian Newsome + Version: 2024.08.06 +#> -# Initial Configuration -$host.ui.RawUI.WindowTitle = 'Edge Removal - Chris Titus Tech 2023.05.10' -$remove_win32 = @("Microsoft Edge", "Microsoft Edge Update") -$remove_appx = @("MicrosoftEdge") -$skip = @() # Optional: @("DevTools") - -$also_remove_webview = 0 -if ($also_remove_webview -eq 1) { - $remove_win32 += "Microsoft EdgeWebView" - $remove_appx += "WebExperience", "Win32WebViewHost" -} - -# Administrative Privileges Check -$privileges = @( - 'SeSecurityPrivilege', - 'SeTakeOwnershipPrivilege', - 'SeBackupPrivilege', - 'SeRestorePrivilege' -) - -foreach ($privilege in $privileges) { - [System.Diagnostics.Process]::SetPrivilege($privilege, 2) -} - -# Edge Removal Procedures -$processesToShutdown = @( - 'explorer', 'Widgets', 'widgetservice', 'msedgewebview2', 'MicrosoftEdge*', 'chredge', - 'msedge', 'edge', 'msteams', 'msfamily', 'WebViewHost', 'Clipchamp' -) - -Stop-Process -Name "explorer" -Force -ErrorAction SilentlyContinue -$processesToShutdown | ForEach-Object { - Stop-Process -Name $_ -Force -ErrorAction SilentlyContinue -} - -$MS = ($env:ProgramFiles, ${env:ProgramFiles(x86)})[[Environment]::Is64BitOperatingSystem] + '\Microsoft\Edge\Application\msedge.exe' - -Remove-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\msedge.exe" -Recurse -ErrorAction SilentlyContinue -Remove-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\ie_to_edge_stub.exe" -Recurse -ErrorAction SilentlyContinue -Remove-Item -Path 'Registry::HKEY_Users\S-1-5-21*\Software\Classes\microsoft-edge' -Recurse -ErrorAction SilentlyContinue -Remove-Item -Path 'Registry::HKEY_Users\S-1-5-21*\Software\Classes\MSEdgeHTM' -Recurse -ErrorAction SilentlyContinue - -New-Item -Path "HKLM:\SOFTWARE\Classes\microsoft-edge\shell\open\command" -Force -ErrorAction SilentlyContinue -Set-ItemProperty -Path "HKLM:\SOFTWARE\Classes\microsoft-edge\shell\open\command" -Name '(Default)' -Value "`"$MS`" --single-argument %%1" -Force -ErrorAction SilentlyContinue - -New-Item -Path "HKLM:\SOFTWARE\Classes\MSEdgeHTM\shell\open\command" -Force -ErrorAction SilentlyContinue -Set-ItemProperty -Path "HKLM:\SOFTWARE\Classes\MSEdgeHTM\shell\open\command" -Name '(Default)' -Value "`"$MS`" --single-argument %%1" -Force -ErrorAction SilentlyContinue - -$registryPaths = @('HKLM:\SOFTWARE\Policies', 'HKLM:\SOFTWARE', 'HKLM:\SOFTWARE\WOW6432Node') -$edgeProperties = @('InstallDefault', 'Install{56EB18F8-B008-4CBD-B6D2-8C97FE7E9062}', 'Install{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}') -foreach ($path in $registryPaths) { - foreach ($prop in $edgeProperties) { - Remove-ItemProperty -Path "$path\Microsoft\EdgeUpdate" -Name $prop -Force -ErrorAction SilentlyContinue - } +# Define constants and initial configuration +$ScriptVersion = "2024.08.06" +$EdgeProcessesToShutdown = @('explorer', 'Widgets', 'widgetservice', 'msedgewebview2', 'MicrosoftEdge*', 'chredge', 'msedge', 'edge', 'msteams', 'msfamily', 'WebViewHost', 'Clipchamp') +$EdgeRemovalOptions = @{ + RemoveWin32 = @("Microsoft Edge", "Microsoft Edge Update") + RemoveAppx = @("MicrosoftEdge") + Skip = @() # Optional: @("DevTools") + AlsoRemoveWebView = $false } -$edgeupdate = 'Microsoft\EdgeUpdate\Clients\{56EB18F8-B008-4CBD-B6D2-8C97FE7E9062}' -$webvupdate = 'Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}' -$on_actions = @('on-os-upgrade', 'on-logon', 'on-logon-autolaunch', 'on-logon-startup-boost') -$registryBases = @('HKLM:\SOFTWARE', 'HKLM:\SOFTWARE\Wow6432Node') -foreach ($base in $registryBases) { - foreach ($launch in $on_actions) { - Remove-Item -Path "$base\$edgeupdate\Commands\$launch" -Force -ErrorAction SilentlyContinue - Remove-Item -Path "$base\$webvupdate\Commands\$launch" -Force -ErrorAction SilentlyContinue +# Function to check if the script is running with administrative privileges +function Test-Admin { + if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { + Write-Error "The script must be run as an Administrator." + exit 1 } } -$registryPaths = @('HKCU:', 'HKLM:') -$nodes = @('', '\Wow6432Node') -foreach ($regPath in $registryPaths) { - foreach ($node in $nodes) { - foreach ($i in $remove_win32) { - Remove-ItemProperty -Path "$regPath\SOFTWARE${node}\Microsoft\Windows\CurrentVersion\Uninstall\$i" -Name 'NoRemove' -Force -ErrorAction SilentlyContinue - New-Item -Path "$regPath\SOFTWARE${node}\Microsoft\EdgeUpdateDev" -Force | Out-Null - Set-ItemProperty -Path "$regPath\SOFTWARE${node}\Microsoft\EdgeUpdateDev" -Name 'AllowUninstall' -Value 1 -Type Dword -Force +# Function to stop Edge-related processes +function Stop-EdgeProcesses { + param([string[]]$ProcessesToStop) + foreach ($process in $ProcessesToStop) { + try { + Stop-Process -Name $process -Force -ErrorAction Stop + Write-Output "Successfully stopped process: $process" + } catch { + Write-Error "Failed to stop process: $process. $_" } } } -$foldersToSearch = @('LocalApplicationData', 'ProgramFilesX86', 'ProgramFiles') | ForEach-Object { - [Environment]::GetFolderPath($_) -} - -$edges = @() -$bhoFiles = @() - -foreach ($folder in $foldersToSearch) { - $bhoFiles += Get-ChildItem -Path "$folder\Microsoft\Edge*\ie_to_edge_stub.exe" -Recurse -ErrorAction SilentlyContinue - - $edges += Get-ChildItem -Path "$folder\Microsoft\Edge*\setup.exe" -Recurse -ErrorAction SilentlyContinue | - Where-Object { $_.FullName -notlike '*EdgeWebView*' } -} - -$destinationDir = "$env:SystemDrive\Scripts" -New-Item -Path $destinationDir -ItemType Directory -ErrorAction SilentlyContinue | Out-Null - -foreach ($bhoFile in $bhoFiles) { - if (Test-Path $bhoFile) { +# Function to remove registry entries related to Microsoft Edge +function Remove-EdgeRegistryEntries { + param([string[]]$RegistryPaths) + foreach ($path in $RegistryPaths) { try { - Copy-Item -Path $bhoFile -Destination "$destinationDir\ie_to_edge_stub.exe" -Force - } catch { } - } -} - -## Work on Appx Removals -$provisioned = Get-AppxProvisionedPackage -Online -$appxpackage = Get-AppxPackage -AllUsers -$eol = @() - -$store = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Store' -$storeP = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Store\InstalledApplications' -foreach ($app in $appxpackage) { - $name = $app.Name - if ($app.Name -eq "Microsoft.Edge") { - $eol += $name - } elseif ($app.Name -eq "Microsoft.EdgeBeta" -or $app.Name -eq "Microsoft.EdgeDev" -or $app.Name -eq "Microsoft.EdgeCanary" -or $app.Name -eq "Microsoft.MicrosoftEdge") { - $eol += $name + Remove-Item -Path $path -Recurse -Force -ErrorAction Stop + Write-Output "Successfully removed registry path: $path" + } catch { + Write-Error "Failed to remove registry path: $path. $_" + } } } -$eolApps = $provisioned | Where-Object { $eol -contains $_.DisplayName } - -foreach ($edge in $eolApps) { - $edgeName = $edge.DisplayName - if (-not ($skip -contains $edgeName)) { +# Function to remove Microsoft Edge AppX packages +function Remove-EdgeAppxPackages { + param([string[]]$AppxPackagesToRemove) + $provisionedPackages = Get-AppxProvisionedPackage -Online + foreach ($package in $AppxPackagesToRemove) { try { - Remove-AppxProvisionedPackage -Online -PackageName $edgeName -ErrorAction SilentlyContinue - } catch { } + $packagesToRemove = $provisionedPackages | Where-Object { $_.DisplayName -like "*$package*" } + foreach ($pkg in $packagesToRemove) { + Remove-AppxProvisionedPackage -Online -PackageName $pkg.PackageName -ErrorAction Stop + Write-Output "Successfully removed provisioned package: $pkg.DisplayName" + } + + $installedPackages = Get-AppxPackage -AllUsers | Where-Object { $_.PackageFullName -like "*$package*" } + foreach ($pkg in $installedPackages) { + Remove-AppxPackage -Package $pkg.PackageFullName -AllUsers -ErrorAction Stop + Write-Output "Successfully removed installed package: $pkg.PackageFullName" + } + } catch { + Write-Error "Failed to remove AppX package: $package. $_" + } } } -foreach ($edge in $appxpackage) { - $edgeName = $edge.Name - if ($eol -contains $edgeName) { - if (-not ($skip -contains $edgeName)) { +# Function to remove shortcuts related to Microsoft Edge +function Remove-EdgeShortcuts { + param([string[]]$ShortcutPaths) + foreach ($path in $ShortcutPaths) { + if (Test-Path $path) { try { - Remove-AppxPackage -Package $edgeName -AllUsers -ErrorAction SilentlyContinue - } catch { } + Remove-Item -Path $path -Force -ErrorAction Stop + Write-Output "Successfully removed shortcut: $path" + } catch { + Write-Error "Failed to remove shortcut: $path. $_" + } } } } -## Redirect shortcuts -$shortcut_path = "$env:Public\Desktop" -$shortcut_file = 'Microsoft Edge.lnk' -$full_path = Join-Path -Path $shortcut_path -ChildPath $shortcut_file - -if (Test-Path $full_path) { - Remove-Item -Path $full_path -Force -ErrorAction SilentlyContinue -} - -$shortcut_path = "$env:ProgramData\Microsoft\Windows\Start Menu\Programs" -$shortcut_file = 'Microsoft Edge.lnk' -$full_path = Join-Path -Path $shortcut_path -ChildPath $shortcut_file - -if (Test-Path $full_path) { - Remove-Item -Path $full_path -Force -ErrorAction SilentlyContinue -} - -$edgePolicy = 'HKLM:\SOFTWARE\Policies\Microsoft\Edge' -if (-not (Test-Path $edgePolicy)) { - New-Item -Path $edgePolicy -Force | Out-Null -} - -$edgePrefs = @{ - 'Dword' = @{ - 'BrowserReplacementEnabled' = 1 - 'HideFirstRunExperience' = 1 - 'HideImportEdgeFavoritesPrompt' = 1 - 'HideSyncSetupExperience' = 1 - 'FavoritesBarVisibility' = 1 - } - 'String' = @{ - 'AutoplayAllowed' = 'AllowOnce' +# Function to configure Edge policy settings +function Configure-EdgePolicy { + param([hashtable]$PolicySettings) + $edgePolicyPath = 'HKLM:\SOFTWARE\Policies\Microsoft\Edge' + if (-not (Test-Path $edgePolicyPath)) { + try { + New-Item -Path $edgePolicyPath -Force | Out-Null + Write-Output "Created Edge policy registry path: $edgePolicyPath" + } catch { + Write-Error "Failed to create Edge policy registry path: $edgePolicyPath. $_" + } } -} -foreach ($entryType in $edgePrefs.Keys) { - foreach ($prefName in $edgePrefs[$entryType].Keys) { - Set-ItemProperty -Path $edgePolicy -Name $prefName -Value $edgePrefs[$entryType][$prefName] -Type $entryType -Force + foreach ($entryType in $PolicySettings.Keys) { + foreach ($prefName in $PolicySettings[$entryType].Keys) { + try { + Set-ItemProperty -Path $edgePolicyPath -Name $prefName -Value $PolicySettings[$entryType][$prefName] -Type $entryType -Force + Write-Output "Successfully set Edge policy: $prefName = $($PolicySettings[$entryType][$prefName])" + } catch { + Write-Error "Failed to set Edge policy: $prefName. $_" + } + } } } -# Output Results -Write-Host "Edge Removal Complete" -ForegroundColor Green - -# Define constants and initial configuration -$ScriptVersion = "2023.05.10" -$EdgeProcessesToShutdown = @('explorer', 'Widgets', 'widgetservice', 'msedgewebview2', 'MicrosoftEdge*', 'chredge', 'msedge', 'edge', 'msteams', 'msfamily', 'WebViewHost', 'Clipchamp') -$EdgeRemovalOptions = @{ - RemoveWin32 = @("Microsoft Edge", "Microsoft Edge Update") - RemoveAppx = @("MicrosoftEdge") - Skip = @() # Optional: @("DevTools") - AlsoRemoveWebView = $false -} - -# Define main function to remove Microsoft Edge components -function Remove-MicrosoftEdge { - [CmdletBinding()] - param() - - # Function to shutdown processes related to Microsoft Edge - function Stop-EdgeProcesses { - $EdgeProcessesToShutdown | ForEach-Object { - Stop-Process -Name $_ -Force -ErrorAction SilentlyContinue +# Main execution +try { + Test-Admin + Stop-EdgeProcesses -ProcessesToStop $EdgeProcessesToShutdown + Remove-EdgeRegistryEntries -RegistryPaths @( + "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\msedge.exe", + "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\ie_to_edge_stub.exe", + "Registry::HKEY_Users\S-1-5-21*\Software\Classes\microsoft-edge", + "Registry::HKEY_Users\S-1-5-21*\Software\Classes\MSEdgeHTM" + ) + Remove-EdgeAppxPackages -AppxPackagesToRemove $EdgeRemovalOptions.RemoveAppx + Remove-EdgeShortcuts -ShortcutPaths @( + "$env:Public\Desktop\Microsoft Edge.lnk", + "$env:ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Edge.lnk" + ) + Configure-EdgePolicy -PolicySettings @{ + 'Dword' = @{ + 'BrowserReplacementEnabled' = 1 + 'HideFirstRunExperience' = 1 + 'HideImportEdgeFavoritesPrompt' = 1 + 'HideSyncSetupExperience' = 1 + 'FavoritesBarVisibility' = 1 } - } - - # Function to remove registry entries related to Microsoft Edge - function Remove-EdgeRegistryEntries { - # Clean up certain registry entries - Remove-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\msedge.exe" -Recurse -ErrorAction SilentlyContinue - Remove-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\ie_to_edge_stub.exe" -Recurse -ErrorAction SilentlyContinue - Remove-Item -Path 'Registry::HKEY_Users\S-1-5-21*\Software\Classes\microsoft-edge' -Recurse -ErrorAction SilentlyContinue - Remove-Item -Path 'Registry::HKEY_Users\S-1-5-21*\Software\Classes\MSEdgeHTM' -Recurse -ErrorAction SilentlyContinue - - # Create new registry entries - $EdgeExecutablePath = ($env:ProgramFiles, ${env:ProgramFiles(x86)})[[Environment]::Is64BitOperatingSystem] + '\Microsoft\Edge\Application\msedge.exe' - New-Item -Path "HKLM:\SOFTWARE\Classes\microsoft-edge\shell\open\command" -Force -ErrorAction SilentlyContinue - Set-ItemProperty -Path "HKLM:\SOFTWARE\Classes\microsoft-edge\shell\open\command" -Name '(Default)' -Value "`"$EdgeExecutablePath`" --single-argument %%1" -Force -ErrorAction SilentlyContinue - - New-Item -Path "HKLM:\SOFTWARE\Classes\MSEdgeHTM\shell\open\command" -Force -ErrorAction SilentlyContinue - Set-ItemProperty -Path "HKLM:\SOFTWARE\Classes\MSEdgeHTM\shell\open\command" -Name '(Default)' -Value "`"$EdgeExecutablePath`" --single-argument %%1" -Force -ErrorAction SilentlyContinue - } - - # Function to remove Microsoft Edge AppX packages - function Remove-EdgeAppxPackages { - $EdgeRemovalOptions.RemoveAppx | ForEach-Object { - # Remove provisioned packages - Get-AppxProvisionedPackage -Online | Where-Object { $_.PackageName -like "*$_*" -and $EdgeRemovalOptions.Skip -notcontains $_.PackageName } | Remove-AppxProvisionedPackage -Online -AllUsers -ErrorAction SilentlyContinue - - # Remove installed packages - Get-AppxPackage -AllUsers | Where-Object { $_.PackageFullName -like "*$_*" -and $EdgeRemovalOptions.Skip -notcontains $_.PackageFullName } | Remove-AppxPackage -AllUsers -ErrorAction SilentlyContinue + 'String' = @{ + 'AutoplayAllowed' = 'AllowOnce' } } - - # Function to remove Microsoft Edge processes, registry entries, and AppX packages - try { - Stop-EdgeProcesses - Remove-EdgeRegistryEntries - Remove-EdgeAppxPackages - Write-Output "Microsoft Edge components have been successfully removed." - } catch { - Write-Error "Failed to remove Microsoft Edge components: $_" - } + Write-Output "Microsoft Edge components have been successfully removed." +} catch { + Write-Error "An error occurred during execution: $_" } - -# Execute the main function -Remove-MicrosoftEdge \ No newline at end of file From e25cdd8fbc8dbf4d8e5acd94fa2260e9cd2e8405 Mon Sep 17 00:00:00 2001 From: Taylor Christian Newsome <86472964+SleepTheGod@users.noreply.github.com> Date: Tue, 6 Aug 2024 06:22:48 -0400 Subject: [PATCH 2/3] Update edgeremoval.ps1 --- edgeremoval.ps1 | 239 ++++++++++++++++++++++++------------------------ 1 file changed, 119 insertions(+), 120 deletions(-) diff --git a/edgeremoval.ps1 b/edgeremoval.ps1 index 9783defff6..d903ddf191 100644 --- a/edgeremoval.ps1 +++ b/edgeremoval.ps1 @@ -1,22 +1,10 @@ -<# -.SYNOPSIS - This script removes Microsoft Edge and related components from the system. - -.DESCRIPTION - This script performs the following tasks: - - Terminates Edge-related processes. - - Removes registry entries associated with Microsoft Edge. - - Uninstalls Edge-related AppX packages. - - Cleans up shortcut files. - - Configures Edge policy settings to prevent reinstallation. - -.NOTES - Updated by Taylor Christian Newsome - Version: 2024.08.06 -#> +# Script Metadata +# Created by AveYo, source: https://raw.githubusercontent.com/AveYo/fox/main/Edge_Removal.bat +# Powershell Conversion and Refactor by Chris Titus Tech +# Updated By Taylor Christian Nesome 8/6/2024 # Define constants and initial configuration -$ScriptVersion = "2024.08.06" +$ScriptVersion = "2023.05.10" $EdgeProcessesToShutdown = @('explorer', 'Widgets', 'widgetservice', 'msedgewebview2', 'MicrosoftEdge*', 'chredge', 'msedge', 'edge', 'msteams', 'msfamily', 'WebViewHost', 'Clipchamp') $EdgeRemovalOptions = @{ RemoveWin32 = @("Microsoft Edge", "Microsoft Edge Update") @@ -25,131 +13,142 @@ $EdgeRemovalOptions = @{ AlsoRemoveWebView = $false } -# Function to check if the script is running with administrative privileges -function Test-Admin { - if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { - Write-Error "The script must be run as an Administrator." - exit 1 - } +# Set window title +$host.ui.RawUI.WindowTitle = "Edge Removal - Chris Titus Tech $ScriptVersion" + +# Administrative Privileges Check +$privileges = @( + 'SeSecurityPrivilege', + 'SeTakeOwnershipPrivilege', + 'SeBackupPrivilege', + 'SeRestorePrivilege' +) + +foreach ($privilege in $privileges) { + [System.Diagnostics.Process]::SetPrivilege($privilege, 2) } -# Function to stop Edge-related processes -function Stop-EdgeProcesses { - param([string[]]$ProcessesToStop) - foreach ($process in $ProcessesToStop) { - try { - Stop-Process -Name $process -Force -ErrorAction Stop - Write-Output "Successfully stopped process: $process" - } catch { - Write-Error "Failed to stop process: $process. $_" +# Define main function to remove Microsoft Edge components +function Remove-MicrosoftEdge { + [CmdletBinding()] + param() + + # Function to shutdown processes related to Microsoft Edge + function Stop-EdgeProcesses { + $EdgeProcessesToShutdown | ForEach-Object { + Stop-Process -Name $_ -Force -ErrorAction SilentlyContinue } } -} -# Function to remove registry entries related to Microsoft Edge -function Remove-EdgeRegistryEntries { - param([string[]]$RegistryPaths) - foreach ($path in $RegistryPaths) { - try { - Remove-Item -Path $path -Recurse -Force -ErrorAction Stop - Write-Output "Successfully removed registry path: $path" - } catch { - Write-Error "Failed to remove registry path: $path. $_" - } + # Function to remove registry entries related to Microsoft Edge + function Remove-EdgeRegistryEntries { + # Clean up certain registry entries + Remove-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\msedge.exe" -Recurse -ErrorAction SilentlyContinue + Remove-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\ie_to_edge_stub.exe" -Recurse -ErrorAction SilentlyContinue + Remove-Item -Path 'Registry::HKEY_Users\S-1-5-21*\Software\Classes\microsoft-edge' -Recurse -ErrorAction SilentlyContinue + Remove-Item -Path 'Registry::HKEY_Users\S-1-5-21*\Software\Classes\MSEdgeHTM' -Recurse -ErrorAction SilentlyContinue + + # Create new registry entries + $EdgeExecutablePath = ($env:ProgramFiles, ${env:ProgramFiles(x86)})[[Environment]::Is64BitOperatingSystem] + '\Microsoft\Edge\Application\msedge.exe' + New-Item -Path "HKLM:\SOFTWARE\Classes\microsoft-edge\shell\open\command" -Force -ErrorAction SilentlyContinue + Set-ItemProperty -Path "HKLM:\SOFTWARE\Classes\microsoft-edge\shell\open\command" -Name '(Default)' -Value "`"$EdgeExecutablePath`" --single-argument %%1" -Force -ErrorAction SilentlyContinue + + New-Item -Path "HKLM:\SOFTWARE\Classes\MSEdgeHTM\shell\open\command" -Force -ErrorAction SilentlyContinue + Set-ItemProperty -Path "HKLM:\SOFTWARE\Classes\MSEdgeHTM\shell\open\command" -Name '(Default)' -Value "`"$EdgeExecutablePath`" --single-argument %%1" -Force -ErrorAction SilentlyContinue } -} -# Function to remove Microsoft Edge AppX packages -function Remove-EdgeAppxPackages { - param([string[]]$AppxPackagesToRemove) - $provisionedPackages = Get-AppxProvisionedPackage -Online - foreach ($package in $AppxPackagesToRemove) { - try { - $packagesToRemove = $provisionedPackages | Where-Object { $_.DisplayName -like "*$package*" } - foreach ($pkg in $packagesToRemove) { - Remove-AppxProvisionedPackage -Online -PackageName $pkg.PackageName -ErrorAction Stop - Write-Output "Successfully removed provisioned package: $pkg.DisplayName" - } + # Function to remove Microsoft Edge AppX packages + function Remove-EdgeAppxPackages { + $EdgeRemovalOptions.RemoveAppx | ForEach-Object { + # Remove provisioned packages + Get-AppxProvisionedPackage -Online | Where-Object { $_.PackageName -like "*$_*" -and $EdgeRemovalOptions.Skip -notcontains $_.PackageName } | Remove-AppxProvisionedPackage -Online -AllUsers -ErrorAction SilentlyContinue - $installedPackages = Get-AppxPackage -AllUsers | Where-Object { $_.PackageFullName -like "*$package*" } - foreach ($pkg in $installedPackages) { - Remove-AppxPackage -Package $pkg.PackageFullName -AllUsers -ErrorAction Stop - Write-Output "Successfully removed installed package: $pkg.PackageFullName" - } - } catch { - Write-Error "Failed to remove AppX package: $package. $_" + # Remove installed packages + Get-AppxPackage -AllUsers | Where-Object { $_.PackageFullName -like "*$_*" -and $EdgeRemovalOptions.Skip -notcontains $_.PackageFullName } | Remove-AppxPackage -AllUsers -ErrorAction SilentlyContinue } } -} -# Function to remove shortcuts related to Microsoft Edge -function Remove-EdgeShortcuts { - param([string[]]$ShortcutPaths) - foreach ($path in $ShortcutPaths) { - if (Test-Path $path) { - try { - Remove-Item -Path $path -Force -ErrorAction Stop - Write-Output "Successfully removed shortcut: $path" - } catch { - Write-Error "Failed to remove shortcut: $path. $_" + # Function to remove unnecessary shortcuts + function Remove-Shortcuts { + $shortcutPaths = @( + "$env:Public\Desktop\Microsoft Edge.lnk", + "$env:ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Edge.lnk" + ) + + $shortcutPaths | ForEach-Object { + if (Test-Path $_) { + Remove-Item -Path $_ -Force -ErrorAction SilentlyContinue } } } -} -# Function to configure Edge policy settings -function Configure-EdgePolicy { - param([hashtable]$PolicySettings) - $edgePolicyPath = 'HKLM:\SOFTWARE\Policies\Microsoft\Edge' - if (-not (Test-Path $edgePolicyPath)) { - try { - New-Item -Path $edgePolicyPath -Force | Out-Null - Write-Output "Created Edge policy registry path: $edgePolicyPath" - } catch { - Write-Error "Failed to create Edge policy registry path: $edgePolicyPath. $_" + # Function to configure Edge policies + function Configure-EdgePolicies { + $edgePolicy = 'HKLM:\SOFTWARE\Policies\Microsoft\Edge' + if (-not (Test-Path $edgePolicy)) { + New-Item -Path $edgePolicy -Force | Out-Null } - } - foreach ($entryType in $PolicySettings.Keys) { - foreach ($prefName in $PolicySettings[$entryType].Keys) { - try { - Set-ItemProperty -Path $edgePolicyPath -Name $prefName -Value $PolicySettings[$entryType][$prefName] -Type $entryType -Force - Write-Output "Successfully set Edge policy: $prefName = $($PolicySettings[$entryType][$prefName])" - } catch { - Write-Error "Failed to set Edge policy: $prefName. $_" + $edgePrefs = @{ + 'Dword' = @{ + 'BrowserReplacementEnabled' = 1 + 'HideFirstRunExperience' = 1 + 'HideImportEdgeFavoritesPrompt' = 1 + 'HideSyncSetupExperience' = 1 + 'FavoritesBarVisibility' = 1 + } + 'String' = @{ + 'AutoplayAllowed' = 'AllowOnce' + } + } + + foreach ($entryType in $edgePrefs.Keys) { + foreach ($prefName in $edgePrefs[$entryType].Keys) { + Set-ItemProperty -Path $edgePolicy -Name $prefName -Value $edgePrefs[$entryType][$prefName] -Type $entryType -Force } } } -} -# Main execution -try { - Test-Admin - Stop-EdgeProcesses -ProcessesToStop $EdgeProcessesToShutdown - Remove-EdgeRegistryEntries -RegistryPaths @( - "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\msedge.exe", - "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\ie_to_edge_stub.exe", - "Registry::HKEY_Users\S-1-5-21*\Software\Classes\microsoft-edge", - "Registry::HKEY_Users\S-1-5-21*\Software\Classes\MSEdgeHTM" - ) - Remove-EdgeAppxPackages -AppxPackagesToRemove $EdgeRemovalOptions.RemoveAppx - Remove-EdgeShortcuts -ShortcutPaths @( - "$env:Public\Desktop\Microsoft Edge.lnk", - "$env:ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Edge.lnk" - ) - Configure-EdgePolicy -PolicySettings @{ - 'Dword' = @{ - 'BrowserReplacementEnabled' = 1 - 'HideFirstRunExperience' = 1 - 'HideImportEdgeFavoritesPrompt' = 1 - 'HideSyncSetupExperience' = 1 - 'FavoritesBarVisibility' = 1 + # Function to remove backup files and folders + function Remove-BackupFiles { + $foldersToSearch = @('LocalApplicationData', 'ProgramFilesX86', 'ProgramFiles') | ForEach-Object { + [Environment]::GetFolderPath($_) + } + + $bhoFiles = @() + $edges = @() + + foreach ($folder in $foldersToSearch) { + $bhoFiles += Get-ChildItem -Path "$folder\Microsoft\Edge*\ie_to_edge_stub.exe" -Recurse -ErrorAction SilentlyContinue + $edges += Get-ChildItem -Path "$folder\Microsoft\Edge*\setup.exe" -Recurse -ErrorAction SilentlyContinue | + Where-Object { $_.FullName -notlike '*EdgeWebView*' } } - 'String' = @{ - 'AutoplayAllowed' = 'AllowOnce' + + $destinationDir = "$env:SystemDrive\Scripts" + New-Item -Path $destinationDir -ItemType Directory -ErrorAction SilentlyContinue | Out-Null + + foreach ($bhoFile in $bhoFiles) { + if (Test-Path $bhoFile) { + try { + Copy-Item -Path $bhoFile -Destination "$destinationDir\ie_to_edge_stub.exe" -Force + } catch { } + } } } - Write-Output "Microsoft Edge components have been successfully removed." -} catch { - Write-Error "An error occurred during execution: $_" + + # Run all functions + try { + Stop-EdgeProcesses + Remove-EdgeRegistryEntries + Remove-EdgeAppxPackages + Remove-Shortcuts + Configure-EdgePolicies + Remove-BackupFiles + Write-Output "Microsoft Edge components have been successfully removed." + } catch { + Write-Error "Failed to remove Microsoft Edge components: $_" + } } + +# Execute the main function +Remove-MicrosoftEdge From b7ac573707a7e7ac57dc6d1963034d4c503ce541 Mon Sep 17 00:00:00 2001 From: Taylor Christian Newsome <86472964+SleepTheGod@users.noreply.github.com> Date: Tue, 6 Aug 2024 06:27:32 -0400 Subject: [PATCH 3/3] Update edgeremoval.ps1 --- edgeremoval.ps1 | 235 +++++++++++++++++++++++++----------------------- 1 file changed, 122 insertions(+), 113 deletions(-) diff --git a/edgeremoval.ps1 b/edgeremoval.ps1 index d903ddf191..f2bc89af3f 100644 --- a/edgeremoval.ps1 +++ b/edgeremoval.ps1 @@ -4,7 +4,25 @@ # Updated By Taylor Christian Nesome 8/6/2024 # Define constants and initial configuration -$ScriptVersion = "2023.05.10" +<# +.SYNOPSIS + This script removes Microsoft Edge and related components from the system. + +.DESCRIPTION + This script performs the following tasks: + - Terminates Edge-related processes. + - Removes registry entries associated with Microsoft Edge. + - Uninstalls Edge-related AppX packages. + - Cleans up shortcut files. + - Configures Edge policy settings to prevent reinstallation. + +.NOTES + Updated by Taylor Christian Newsome + Version: 2024.08.06 +#> + +# Define constants and initial configuration +$ScriptVersion = "2024.08.06" $EdgeProcessesToShutdown = @('explorer', 'Widgets', 'widgetservice', 'msedgewebview2', 'MicrosoftEdge*', 'chredge', 'msedge', 'edge', 'msteams', 'msfamily', 'WebViewHost', 'Clipchamp') $EdgeRemovalOptions = @{ RemoveWin32 = @("Microsoft Edge", "Microsoft Edge Update") @@ -13,142 +31,133 @@ $EdgeRemovalOptions = @{ AlsoRemoveWebView = $false } -# Set window title -$host.ui.RawUI.WindowTitle = "Edge Removal - Chris Titus Tech $ScriptVersion" - -# Administrative Privileges Check -$privileges = @( - 'SeSecurityPrivilege', - 'SeTakeOwnershipPrivilege', - 'SeBackupPrivilege', - 'SeRestorePrivilege' -) - -foreach ($privilege in $privileges) { - [System.Diagnostics.Process]::SetPrivilege($privilege, 2) +# Function to check if the script is running with administrative privileges +function Test-Admin { + if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { + Write-Error "The script must be run as an Administrator." + exit 1 + } } -# Define main function to remove Microsoft Edge components -function Remove-MicrosoftEdge { - [CmdletBinding()] - param() - - # Function to shutdown processes related to Microsoft Edge - function Stop-EdgeProcesses { - $EdgeProcessesToShutdown | ForEach-Object { - Stop-Process -Name $_ -Force -ErrorAction SilentlyContinue +# Function to stop Edge-related processes +function Stop-EdgeProcesses { + param([string[]]$ProcessesToStop) + foreach ($process in $ProcessesToStop) { + try { + Stop-Process -Name $process -Force -ErrorAction Stop + Write-Output "Successfully stopped process: $process" + } catch { + Write-Error "Failed to stop process: $process. $_" } } +} - # Function to remove registry entries related to Microsoft Edge - function Remove-EdgeRegistryEntries { - # Clean up certain registry entries - Remove-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\msedge.exe" -Recurse -ErrorAction SilentlyContinue - Remove-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\ie_to_edge_stub.exe" -Recurse -ErrorAction SilentlyContinue - Remove-Item -Path 'Registry::HKEY_Users\S-1-5-21*\Software\Classes\microsoft-edge' -Recurse -ErrorAction SilentlyContinue - Remove-Item -Path 'Registry::HKEY_Users\S-1-5-21*\Software\Classes\MSEdgeHTM' -Recurse -ErrorAction SilentlyContinue - - # Create new registry entries - $EdgeExecutablePath = ($env:ProgramFiles, ${env:ProgramFiles(x86)})[[Environment]::Is64BitOperatingSystem] + '\Microsoft\Edge\Application\msedge.exe' - New-Item -Path "HKLM:\SOFTWARE\Classes\microsoft-edge\shell\open\command" -Force -ErrorAction SilentlyContinue - Set-ItemProperty -Path "HKLM:\SOFTWARE\Classes\microsoft-edge\shell\open\command" -Name '(Default)' -Value "`"$EdgeExecutablePath`" --single-argument %%1" -Force -ErrorAction SilentlyContinue - - New-Item -Path "HKLM:\SOFTWARE\Classes\MSEdgeHTM\shell\open\command" -Force -ErrorAction SilentlyContinue - Set-ItemProperty -Path "HKLM:\SOFTWARE\Classes\MSEdgeHTM\shell\open\command" -Name '(Default)' -Value "`"$EdgeExecutablePath`" --single-argument %%1" -Force -ErrorAction SilentlyContinue - } - - # Function to remove Microsoft Edge AppX packages - function Remove-EdgeAppxPackages { - $EdgeRemovalOptions.RemoveAppx | ForEach-Object { - # Remove provisioned packages - Get-AppxProvisionedPackage -Online | Where-Object { $_.PackageName -like "*$_*" -and $EdgeRemovalOptions.Skip -notcontains $_.PackageName } | Remove-AppxProvisionedPackage -Online -AllUsers -ErrorAction SilentlyContinue - - # Remove installed packages - Get-AppxPackage -AllUsers | Where-Object { $_.PackageFullName -like "*$_*" -and $EdgeRemovalOptions.Skip -notcontains $_.PackageFullName } | Remove-AppxPackage -AllUsers -ErrorAction SilentlyContinue +# Function to remove registry entries related to Microsoft Edge +function Remove-EdgeRegistryEntries { + param([string[]]$RegistryPaths) + foreach ($path in $RegistryPaths) { + try { + Remove-Item -Path $path -Recurse -Force -ErrorAction Stop + Write-Output "Successfully removed registry path: $path" + } catch { + Write-Error "Failed to remove registry path: $path. $_" } } +} - # Function to remove unnecessary shortcuts - function Remove-Shortcuts { - $shortcutPaths = @( - "$env:Public\Desktop\Microsoft Edge.lnk", - "$env:ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Edge.lnk" - ) - - $shortcutPaths | ForEach-Object { - if (Test-Path $_) { - Remove-Item -Path $_ -Force -ErrorAction SilentlyContinue +# Function to remove Microsoft Edge AppX packages +function Remove-EdgeAppxPackages { + param([string[]]$AppxPackagesToRemove) + $provisionedPackages = Get-AppxProvisionedPackage -Online + foreach ($package in $AppxPackagesToRemove) { + try { + $packagesToRemove = $provisionedPackages | Where-Object { $_.DisplayName -like "*$package*" } + foreach ($pkg in $packagesToRemove) { + Remove-AppxProvisionedPackage -Online -PackageName $pkg.PackageName -ErrorAction Stop + Write-Output "Successfully removed provisioned package: $pkg.DisplayName" } - } - } - - # Function to configure Edge policies - function Configure-EdgePolicies { - $edgePolicy = 'HKLM:\SOFTWARE\Policies\Microsoft\Edge' - if (-not (Test-Path $edgePolicy)) { - New-Item -Path $edgePolicy -Force | Out-Null - } - $edgePrefs = @{ - 'Dword' = @{ - 'BrowserReplacementEnabled' = 1 - 'HideFirstRunExperience' = 1 - 'HideImportEdgeFavoritesPrompt' = 1 - 'HideSyncSetupExperience' = 1 - 'FavoritesBarVisibility' = 1 - } - 'String' = @{ - 'AutoplayAllowed' = 'AllowOnce' + $installedPackages = Get-AppxPackage -AllUsers | Where-Object { $_.PackageFullName -like "*$package*" } + foreach ($pkg in $installedPackages) { + Remove-AppxPackage -Package $pkg.PackageFullName -AllUsers -ErrorAction Stop + Write-Output "Successfully removed installed package: $pkg.PackageFullName" } + } catch { + Write-Error "Failed to remove AppX package: $package. $_" } + } +} - foreach ($entryType in $edgePrefs.Keys) { - foreach ($prefName in $edgePrefs[$entryType].Keys) { - Set-ItemProperty -Path $edgePolicy -Name $prefName -Value $edgePrefs[$entryType][$prefName] -Type $entryType -Force +# Function to remove shortcuts related to Microsoft Edge +function Remove-EdgeShortcuts { + param([string[]]$ShortcutPaths) + foreach ($path in $ShortcutPaths) { + if (Test-Path $path) { + try { + Remove-Item -Path $path -Force -ErrorAction Stop + Write-Output "Successfully removed shortcut: $path" + } catch { + Write-Error "Failed to remove shortcut: $path. $_" } } } +} - # Function to remove backup files and folders - function Remove-BackupFiles { - $foldersToSearch = @('LocalApplicationData', 'ProgramFilesX86', 'ProgramFiles') | ForEach-Object { - [Environment]::GetFolderPath($_) - } - - $bhoFiles = @() - $edges = @() - - foreach ($folder in $foldersToSearch) { - $bhoFiles += Get-ChildItem -Path "$folder\Microsoft\Edge*\ie_to_edge_stub.exe" -Recurse -ErrorAction SilentlyContinue - $edges += Get-ChildItem -Path "$folder\Microsoft\Edge*\setup.exe" -Recurse -ErrorAction SilentlyContinue | - Where-Object { $_.FullName -notlike '*EdgeWebView*' } +# Function to configure Edge policy settings +function Configure-EdgePolicy { + param([hashtable]$PolicySettings) + $edgePolicyPath = 'HKLM:\SOFTWARE\Policies\Microsoft\Edge' + if (-not (Test-Path $edgePolicyPath)) { + try { + New-Item -Path $edgePolicyPath -Force | Out-Null + Write-Output "Created Edge policy registry path: $edgePolicyPath" + } catch { + Write-Error "Failed to create Edge policy registry path: $edgePolicyPath. $_" } + } - $destinationDir = "$env:SystemDrive\Scripts" - New-Item -Path $destinationDir -ItemType Directory -ErrorAction SilentlyContinue | Out-Null - - foreach ($bhoFile in $bhoFiles) { - if (Test-Path $bhoFile) { - try { - Copy-Item -Path $bhoFile -Destination "$destinationDir\ie_to_edge_stub.exe" -Force - } catch { } + foreach ($entryType in $PolicySettings.Keys) { + foreach ($prefName in $PolicySettings[$entryType].Keys) { + try { + Set-ItemProperty -Path $edgePolicyPath -Name $prefName -Value $PolicySettings[$entryType][$prefName] -Type $entryType -Force + Write-Output "Successfully set Edge policy: $prefName = $($PolicySettings[$entryType][$prefName])" + } catch { + Write-Error "Failed to set Edge policy: $prefName. $_" } } } +} - # Run all functions - try { - Stop-EdgeProcesses - Remove-EdgeRegistryEntries - Remove-EdgeAppxPackages - Remove-Shortcuts - Configure-EdgePolicies - Remove-BackupFiles - Write-Output "Microsoft Edge components have been successfully removed." - } catch { - Write-Error "Failed to remove Microsoft Edge components: $_" +# Main execution +try { + Test-Admin + Stop-EdgeProcesses -ProcessesToStop $EdgeProcessesToShutdown + Remove-EdgeRegistryEntries -RegistryPaths @( + "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\msedge.exe", + "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\ie_to_edge_stub.exe", + "Registry::HKEY_Users\S-1-5-21*\Software\Classes\microsoft-edge", + "Registry::HKEY_Users\S-1-5-21*\Software\Classes\MSEdgeHTM" + ) + Remove-EdgeAppxPackages -AppxPackagesToRemove $EdgeRemovalOptions.RemoveAppx + Remove-EdgeShortcuts -ShortcutPaths @( + "$env:Public\Desktop\Microsoft Edge.lnk", + "$env:ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Edge.lnk" + ) + Configure-EdgePolicy -PolicySettings @{ + 'Dword' = @{ + 'BrowserReplacementEnabled' = 1 + 'HideFirstRunExperience' = 1 + 'HideImportEdgeFavoritesPrompt' = 1 + 'HideSyncSetupExperience' = 1 + 'FavoritesBarVisibility' = 1 + } + 'String' = @{ + 'AutoplayAllowed' = 'AllowOnce' + } } + Write-Output "Microsoft Edge components have been successfully removed." +} catch { + Write-Error "An error occurred during execution: $_" } -# Execute the main function Remove-MicrosoftEdge