From e66103f57aebb3e58572b38c9dc17b236f1ac5f5 Mon Sep 17 00:00:00 2001 From: Raphire <9938813+Raphire@users.noreply.github.com> Date: Sat, 15 Nov 2025 00:46:39 +0100 Subject: [PATCH] Add task for removing MS Edge & OneDrive when run as other user or sysprep mode #366 --- Regfiles/Sysprep/Uninstall_Microsoft_Edge.reg | 4 ++++ Regfiles/Sysprep/Uninstall_Microsoft_OneDrive.reg | 4 ++++ Win11Debloat.ps1 | 14 ++++++++++++-- 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 Regfiles/Sysprep/Uninstall_Microsoft_Edge.reg create mode 100644 Regfiles/Sysprep/Uninstall_Microsoft_OneDrive.reg diff --git a/Regfiles/Sysprep/Uninstall_Microsoft_Edge.reg b/Regfiles/Sysprep/Uninstall_Microsoft_Edge.reg new file mode 100644 index 0000000..ba0e3ca --- /dev/null +++ b/Regfiles/Sysprep/Uninstall_Microsoft_Edge.reg @@ -0,0 +1,4 @@ +Windows Registry Editor Version 5.00 + +[hkey_users\default\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce] +"UninstallMicrosoftEdge"="cmd.exe /c winget uninstall --accept-source-agreements --disable-interactivity --id Microsoft.Edge" diff --git a/Regfiles/Sysprep/Uninstall_Microsoft_OneDrive.reg b/Regfiles/Sysprep/Uninstall_Microsoft_OneDrive.reg new file mode 100644 index 0000000..10669e4 --- /dev/null +++ b/Regfiles/Sysprep/Uninstall_Microsoft_OneDrive.reg @@ -0,0 +1,4 @@ +Windows Registry Editor Version 5.00 + +[hkey_users\default\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce] +"UninstallMicrosoftOneDrive"="cmd.exe /c winget uninstall --accept-source-agreements --disable-interactivity --id Microsoft.OneDrive" diff --git a/Win11Debloat.ps1 b/Win11Debloat.ps1 index 534c4f5..bd13ed7 100755 --- a/Win11Debloat.ps1 +++ b/Win11Debloat.ps1 @@ -383,8 +383,18 @@ function RemoveApps { Write-Host "Error: WinGet is either not installed or is outdated, $app could not be removed" -ForegroundColor Red } else { - # Uninstall app via winget - Strip-Progress -ScriptBlock { winget uninstall --accept-source-agreements --disable-interactivity --id $app } | Tee-Object -Variable wingetOutput + $appName = $app -replace '\.', '_' + + # Uninstall app via winget, or create a scheduled task to uninstall it later + if ($script:Params.ContainsKey("User")) { + RegImport "Adding scheduled task to uninstall $app for user $(GetUserName)..." "Uninstall_$($appName).reg" + } + elseif ($script:Params.ContainsKey("Sysprep")) { + RegImport "Adding scheduled task to uninstall $app after new users log in..." "Uninstall_$($appName).reg" + } + else { + Strip-Progress -ScriptBlock { winget uninstall --accept-source-agreements --disable-interactivity --id $app } | Tee-Object -Variable wingetOutput + } If (($app -eq "Microsoft.Edge") -and (Select-String -InputObject $wingetOutput -Pattern "Uninstall failed with exit code")) { Write-Host "Unable to uninstall Microsoft Edge via Winget" -ForegroundColor Red