#Requires -RunAsAdministrator <# .SYNOPSIS Nerdy Neighbor - Remove OEM and Windows bloat .DESCRIPTION Removes the PC maker's preinstalled software (HP, Dell, Lenovo, Samsung, Acer, Asus) and a set of Windows apps customers don't use (Xbox, Weather, News, Clipchamp, Copilot, Teams, Solitaire, ...), then stops Windows from quietly reinstalling "suggested" apps. KEPT on purpose: HP Smart, Photos, Media Player, Clock, Mail and Calendar, Calculator, Paint, Notepad, Snipping Tool, Sticky Notes, Camera, Store, Edge, Windows Security, Quick Assist, Phone Link, Outlook, the Xbox sign-in parts Minecraft/Game Pass need, Intel graphics and Dolby audio controls, Spotlight lock-screen pictures, the Start menu layout. McAfee/Norton are left to avremove.nerdyneighbor.net. .NOTES Run: irm debloat.nerdyneighbor.net | iex (elevated Windows PowerShell) It shows the PC maker and asks before changing anything. RMM: $env:NN_DEBLOAT = 'yes'; irm debloat.nerdyneighbor.net | iex Log: C:\ProgramData\NerdyNeighbor\debloat.log Undo: a restore point "Before Nerdy Neighbor debloat" is made first. Removed Store apps can be reinstalled from the Microsoft Store. The HP/Dell/Lenovo/Samsung/Acer/Asus removal code is taken verbatim from Andrew Taylor's RemoveBloat.ps1 (https://github.com/andrew-s-taylor/public, De-Bloat/RemoveBloat.ps1, GPL-3.0), commit ce39945d999568ee67aec9f7571250293fde9689. This script is therefore also licensed GPL-3.0 (see LICENSE). #> # Everything runs inside & { } so that under `irm | iex` nothing leaks into the # tech's PowerShell window afterwards. Use `return`, never `exit`. & { $ErrorActionPreference = 'Stop' [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 $isAdmin = ([Security.Principal.WindowsPrincipal] ` [Security.Principal.WindowsIdentity]::GetCurrent() ).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) if (-not $isAdmin) { Write-Host "" Write-Host " This needs an ELEVATED PowerShell (Run as Administrator)." -ForegroundColor Red Write-Host " Close this window, reopen PowerShell as Administrator, and run again." -ForegroundColor Yellow Write-Host "" return } # --- Logging ----------------------------------------------------------------- $LogDir = Join-Path $env:ProgramData 'NerdyNeighbor' $LogFile = Join-Path $LogDir 'debloat.log' if (-not (Test-Path $LogDir)) { New-Item -ItemType Directory -Path $LogDir -Force | Out-Null } function Write-Log { param([string]$Message, [string]$Level = 'INFO') $line = '{0} [{1}] {2}' -f (Get-Date -Format 'yyyy-MM-dd HH:mm:ss'), $Level, $Message Add-Content -Path $LogFile -Value $line -ErrorAction SilentlyContinue switch ($Level) { 'ERROR' { Write-Host " $Message" -ForegroundColor Red } 'WARN' { Write-Host " $Message" -ForegroundColor Yellow } 'OK' { Write-Host " $Message" -ForegroundColor Green } 'DETAIL'{ Write-Host " $Message" -ForegroundColor DarkGray } default { Write-Host " $Message" -ForegroundColor Gray } } } # Installers/answer files must live where only SYSTEM and Administrators can # write: a new, randomly named folder whose ACL is set as it is created. function New-AdminOnlyDir { param([string]$Name) $path = Join-Path $env:SystemRoot ('Temp\nn-{0}-{1}' -f $Name, [guid]::NewGuid().ToString('N')) $acl = New-Object System.Security.AccessControl.DirectorySecurity $acl.SetAccessRuleProtection($true, $false) foreach ($sid in 'S-1-5-18', 'S-1-5-32-544') { $acl.AddAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule( (New-Object System.Security.Principal.SecurityIdentifier($sid)), 'FullControl', 'ContainerInherit,ObjectInherit', 'None', 'Allow'))) } $acl.SetOwner((New-Object System.Security.Principal.SecurityIdentifier('S-1-5-32-544'))) $di = New-Object System.IO.DirectoryInfo($path) if ($di.Exists) { throw "Work folder $path already exists - not using it." } if ($PSVersionTable.PSEdition -eq 'Core') { [System.IO.FileSystemAclExtensions]::Create($di, $acl) } else { $di.Create($acl) } $path } # --- Registry helpers ---------------------------------------------------------- function Set-Reg { param([string]$Path, [string]$Name, $Value, [string]$Type = 'DWord') try { if (-not (Test-Path $Path)) { New-Item -Path $Path -Force | Out-Null } New-ItemProperty -Path $Path -Name $Name -Value $Value -PropertyType $Type -Force | Out-Null } catch { Write-Log "Could not set $Path\$Name : $($_.Exception.Message)" 'WARN' } } # Runs $Action once for every real user profile AND the Default profile (so new # accounts get the settings too). $Action gets the hive root, e.g. # "Registry::HKEY_USERS\S-1-5-21-...". Hives of users who aren't signed in are # loaded and unloaded again. function Invoke-ForEachUserHive { param([scriptblock]$Action) $hives = @() Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList' -ErrorAction SilentlyContinue | Where-Object { $_.PSChildName -match '^S-1-5-21-' } | ForEach-Object { $p = (Get-ItemProperty $_.PSPath -ErrorAction SilentlyContinue).ProfileImagePath if ($p) { $hives += [pscustomobject]@{ Key = $_.PSChildName; Dat = (Join-Path $p 'NTUSER.DAT') } } } $default = Join-Path $env:SystemDrive 'Users\Default\NTUSER.DAT' if (Test-Path $default) { $hives += [pscustomobject]@{ Key = $null; Dat = $default } } $n = 0 foreach ($h in $hives) { if ($h.Key -and (Test-Path "Registry::HKEY_USERS\$($h.Key)")) { & $Action "Registry::HKEY_USERS\$($h.Key)" continue } if (-not (Test-Path $h.Dat)) { continue } $n++ $mount = "NN_Debloat_$n" & reg.exe load "HKU\$mount" "$($h.Dat)" 2>&1 | Out-Null if ($LASTEXITCODE -ne 0) { Write-Log "Could not load $($h.Dat) (in use?) - skipped." 'WARN'; continue } try { & $Action "Registry::HKEY_USERS\$mount" } finally { [gc]::Collect(); [gc]::WaitForPendingFinalizers() & reg.exe unload "HKU\$mount" 2>&1 | Out-Null } } } # --- What to remove / keep ------------------------------------------------------- # Store (AppX) apps removed for all users, and de-provisioned so new accounts # don't get them. Wildcards allowed. $RemoveAppx = @( # Xbox app + overlays (the sign-in parts below are KEPT for Minecraft/Game Pass) 'Microsoft.XboxApp', 'Microsoft.GamingApp', 'Microsoft.XboxGameOverlay', 'Microsoft.XboxGamingOverlay', 'Microsoft.XboxSpeechToTextOverlay', 'Microsoft.Edge.GameAssist', # News / weather / search / tips 'Microsoft.BingWeather', 'Microsoft.BingNews', 'Microsoft.News', 'Microsoft.BingSearch', 'Microsoft.Getstarted', 'Microsoft.WindowsFeedbackHub', 'Microsoft.WindowsMaps', # Copilot (Windows Copilot + Microsoft 365 Copilot / Office hub - Office apps themselves stay) 'Microsoft.Copilot', 'Microsoft.Windows.Ai.Copilot.Provider', 'Microsoft.MicrosoftOfficeHub', # Teams (personal and new) and other chat 'MicrosoftTeams', 'MSTeams', 'Microsoft.Teams', 'Microsoft.SkypeApp', 'Microsoft.Messaging', 'Microsoft.People', # Misc Microsoft extras 'Clipchamp.Clipchamp', 'Microsoft.MicrosoftSolitaireCollection', 'Microsoft.549981C3F5F10', 'Microsoft.Microsoft3DViewer', 'Microsoft.Print3D', 'Microsoft.MixedReality.Portal', 'Microsoft.Office.Sway', 'Microsoft.Office.Lens', 'Microsoft.Office.OneNote', 'Microsoft.OneConnect', 'Microsoft.Windows.DevHome', 'Microsoft.PowerAutomateDesktop', 'Microsoft.PowerAutomateDesktopCopilotPlugin', 'Microsoft.MicrosoftJournal', 'Microsoft.SysinternalsSuite', 'Microsoft.ZuneVideo', 'MicrosoftCorporationII.MicrosoftFamily', 'Microsoft.RemoteDesktop', # Third-party promos / trials 'SpotifyAB.SpotifyMusic', 'Disney.37853FC22B2CE', 'C27EB4BA.DropboxOEM*', 'RealtimeboardInc.RealtimeBoard', 'king.com.*', 'BytedancePte.Ltd.TikTok', '7EE7776C.LinkedInforWindows', 'Facebook.*', 'AppUp.IntelUnison', 'Intel Unison', 'Intel Connectivity Performance Suite', 'Adobe Creative Cloud All Apps 2-month membership', 'MirametrixInc.GlancebyMirametrix', 'E0469640.SmartAppearance' ) # Never touched, even if something above (or the OEM code below) matches. $KeepAppx = @( 'AD2F1837.HPPrinterControl', # HP Smart 'Microsoft.Windows.Photos', 'Microsoft.ZuneMusic', 'Microsoft.WindowsAlarms', 'microsoft.windowscommunicationsapps', 'Microsoft.GetHelp', 'MicrosoftCorporationII.QuickAssist', 'MicrosoftWindows.CrossDevice', 'Microsoft.YourPhone', 'Microsoft.Xbox.TCUI', 'Microsoft.XboxIdentityProvider', 'AppUp.IntelGraphicsExperience', 'DolbyLaboratories.DolbyAccess', 'DolbyLaboratories.DolbyAudio' ) # --- From RemoveBloat.ps1: its keep-list and the apps Windows refuses to remove --- $WhitelistedApps = @( 'Microsoft.WindowsNotepad', 'Microsoft.CompanyPortal', 'Microsoft.ScreenSketch', 'Microsoft.Paint3D', 'Microsoft.WindowsCalculator', 'Microsoft.WindowsStore', 'Microsoft.Windows.Photos', 'CanonicalGroupLimited.UbuntuonWindows', 'Microsoft.MicrosoftStickyNotes', 'Microsoft.MSPaint', 'Microsoft.WindowsCamera', '.NET Framework', 'Microsoft.HEIFImageExtension', 'Microsoft.StorePurchaseApp', 'Microsoft.VP9VideoExtensions', 'Microsoft.WebMediaExtensions', 'Microsoft.WebpImageExtension', 'Microsoft.DesktopAppInstaller', 'WindSynthBerry', 'MIDIBerry', 'Slack', 'Microsoft.SecHealthUI', 'WavesAudio.MaxxAudioProforDell2019', 'Dell Optimizer Core', 'Dell SupportAssist Remediation', 'Dell SupportAssist OS Recovery Plugin for Dell Update', 'Dell Pair', 'Dell Display Manager 2.0', 'Dell Display Manager 2.1', 'Dell Display Manager 2.2', 'Dell Peripheral Manager', 'MSTeams', 'Microsoft.Paint', 'Microsoft.OutlookForWindows', 'Microsoft.WindowsTerminal', 'Microsoft.MicrosoftEdge.Stable', 'Microsoft.MPEG2VideoExtension', 'Microsoft.HEVCVideoExtension', 'Microsoft.AV1VideoExtension', 'Microsoft.RawImageExtension', 'Microsoft.AVCEncoderVideoExtension' ) #NonRemovable Apps that where getting attempted and the system would reject the uninstall, speeds up debloat and prevents 'initalizing' overlay when removing apps $NonRemovable = @( '1527c705-839a-4832-9118-54d4Bd6a0c89', 'c5e2524a-ea46-4f67-841f-6a9465d9d515', 'E2A4F912-2574-4A75-9BB0-0D023378592B', 'F46D4000-FD22-4DB4-AC8E-4E1DDDE828FE', 'InputApp', 'Microsoft.AAD.BrokerPlugin', 'Microsoft.AccountsControl', 'Microsoft.BioEnrollment', 'Microsoft.CredDialogHost', 'Microsoft.ECApp', 'Microsoft.LockApp', 'Microsoft.MicrosoftEdgeDevToolsClient', 'Microsoft.MicrosoftEdge', 'Microsoft.PPIProjection', 'Microsoft.Win32WebViewHost', 'Microsoft.Windows.Apprep.ChxApp', 'Microsoft.Windows.AssignedAccessLockApp', 'Microsoft.Windows.CapturePicker', 'Microsoft.Windows.CloudExperienceHost', 'Microsoft.Windows.ContentDeliveryManager', 'Microsoft.Windows.Cortana', 'Microsoft.Windows.NarratorQuickStart', 'Microsoft.Windows.ParentalControls', 'Microsoft.Windows.PeopleExperienceHost', 'Microsoft.Windows.PinningConfirmationDialog', 'Microsoft.Windows.SecHealthUI', 'Microsoft.Windows.SecureAssessmentBrowser', 'Microsoft.Windows.ShellExperienceHost', 'Microsoft.Windows.XGpuEjectDialog', 'Microsoft.XboxGameCallableUI', 'Windows.CBSPreview', 'windows.immersivecontrolpanel', 'Windows.PrintDialog', 'Microsoft.VCLibs.140.00', 'Microsoft.Services.Store.Engagement', 'Microsoft.UI.Xaml.2.0', 'Microsoft.AsyncTextService', 'Microsoft.UI.Xaml.CBS', 'Microsoft.Windows.CallingShellApp', 'Microsoft.Windows.OOBENetworkConnectionFlow', 'Microsoft.Windows.PrintQueueActionCenter', 'Microsoft.Windows.StartMenuExperienceHost', 'MicrosoftWindows.Client.CBS', 'MicrosoftWindows.Client.Core', 'MicrosoftWindows.UndockedDevKit', 'NcsiUwpApp', 'Microsoft.NET.Native.Runtime.2.2', 'Microsoft.NET.Native.Framework.2.2', 'Microsoft.UI.Xaml.2.8', 'Microsoft.UI.Xaml.2.7', 'Microsoft.UI.Xaml.2.3', 'Microsoft.UI.Xaml.2.4', 'Microsoft.UI.Xaml.2.1', 'Microsoft.UI.Xaml.2.2', 'Microsoft.UI.Xaml.2.5', 'Microsoft.UI.Xaml.2.6', 'Microsoft.VCLibs.140.00.UWPDesktop', 'MicrosoftWindows.Client.LKG', 'MicrosoftWindows.Client.FileExp', 'Microsoft.WindowsAppRuntime.1.5', 'Microsoft.WindowsAppRuntime.1.3', 'Microsoft.WindowsAppRuntime.1.1', 'Microsoft.WindowsAppRuntime.1.2', 'Microsoft.WindowsAppRuntime.1.4', 'Microsoft.Windows.OOBENetworkCaptivePortal', 'Microsoft.Windows.Search' ) # Our keep-list wins over everything in the OEM section too. # ...except new Teams (MSTeams), which RemoveBloat keeps but we remove. $appstoignore = @($WhitelistedApps + $NonRemovable + $KeepAppx | Where-Object { $_ -ne 'MSTeams' } | Sort-Object -Unique) # HP Connection Optimizer's InstallShield answer file (from RemoveBloat's HPConnOpt.iss). $HPConnOptIss = @' [InstallShield Silent] Version=v7.00 File=Response File [File Transfer] OverwrittenReadOnly=NoToAll [{6468C4A5-E47E-405F-B675-A70A70983EA6}-DlgOrder] Dlg0={6468C4A5-E47E-405F-B675-A70A70983EA6}-SdWelcomeMaint-0 Count=3 Dlg1={6468C4A5-E47E-405F-B675-A70A70983EA6}-MessageBox-0 Dlg2={6468C4A5-E47E-405F-B675-A70A70983EA6}-SdFinishReboot-0 [{6468C4A5-E47E-405F-B675-A70A70983EA6}-SdWelcomeMaint-0] Result=303 [{6468C4A5-E47E-405F-B675-A70A70983EA6}-MessageBox-0] Result=6 [Application] Name=HP Connection Optimizer Version=2.0.18.0 Company=HP Inc. Lang=0409 [{6468C4A5-E47E-405F-B675-A70A70983EA6}-SdFinishReboot-0] Result=1 BootOption=0 '@ # --- Steps ------------------------------------------------------------------------- function New-NNRestorePoint { if (-not (Get-Command Checkpoint-Computer -ErrorAction SilentlyContinue)) { Write-Log 'This PowerShell cannot make restore points - continuing without one.' 'WARN'; return } # Windows only allows one restore point per 24h unless this is 0. $srKey = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore' $old = (Get-ItemProperty $srKey -Name SystemRestorePointCreationFrequency -ErrorAction SilentlyContinue).SystemRestorePointCreationFrequency try { Enable-ComputerRestore -Drive "$env:SystemDrive\" -ErrorAction Stop Set-Reg $srKey 'SystemRestorePointCreationFrequency' 0 Checkpoint-Computer -Description 'Before Nerdy Neighbor debloat' -RestorePointType MODIFY_SETTINGS -ErrorAction Stop Write-Log 'Restore point created: "Before Nerdy Neighbor debloat".' 'OK' } catch { Write-Log "Could not create a restore point ($($_.Exception.Message)) - continuing." 'WARN' } finally { if ($null -eq $old) { Remove-ItemProperty $srKey -Name SystemRestorePointCreationFrequency -ErrorAction SilentlyContinue } else { Set-Reg $srKey 'SystemRestorePointCreationFrequency' $old } } } function Remove-AppxBloat { $removed = New-Object System.Collections.Generic.List[string] $prov = @(Get-AppxProvisionedPackage -Online -ErrorAction SilentlyContinue) $inst = @(Get-AppxPackage -AllUsers -ErrorAction SilentlyContinue) foreach ($pattern in $RemoveAppx) { foreach ($p in ($prov | Where-Object { $_.DisplayName -like $pattern -and $appstoignore -notcontains $_.DisplayName })) { try { Remove-AppxProvisionedPackage -Online -PackageName $p.PackageName -ErrorAction Stop | Out-Null Write-Log "Stopped new accounts getting $($p.DisplayName)" 'DETAIL' } catch { Write-Log "Could not de-provision $($p.DisplayName): $($_.Exception.Message)" 'WARN' } } foreach ($a in ($inst | Where-Object { $_.Name -like $pattern -and $appstoignore -notcontains $_.Name })) { try { Remove-AppxPackage -Package $a.PackageFullName -AllUsers -ErrorAction Stop if (-not $removed.Contains($a.Name)) { $removed.Add($a.Name) } Write-Log "Removed $($a.Name)" 'DETAIL' } catch { Write-Log "Could not remove $($a.Name): $($_.Exception.Message)" 'WARN' } } } , $removed } function Set-WindowsSettings { # No more silently installed "suggested" apps (Candy Crush, TikTok, ...). Set-Reg 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\CloudContent' 'DisableWindowsConsumerFeatures' 1 # Widgets (news feed) off. Set-Reg 'HKLM:\SOFTWARE\Policies\Microsoft\Dsh' 'AllowNewsAndInterests' 0 # Recall (AI screenshot history) off. Set-Reg 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsAI' 'DisableAIDataAnalysis' 1 # Copilot off in Windows and Edge; Edge's Surf game off. Set-Reg 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsCopilot' 'TurnOffWindowsCopilot' 1 Set-Reg 'HKLM:\SOFTWARE\Policies\Microsoft\Edge' 'HubsSidebarEnabled' 0 Set-Reg 'HKLM:\SOFTWARE\Policies\Microsoft\Edge' 'Microsoft365CopilotChatIconEnabled' 0 Set-Reg 'HKLM:\SOFTWARE\Policies\Microsoft\Edge' 'AllowSurfGame' 0 # Game Bar capture pop-ups off (the Xbox app is gone). Set-Reg 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\GameDVR' 'AllowGameDVR' 0 # A few telemetry tasks. foreach ($t in 'Consolidator', 'UsbCeip', 'DmClient', 'DmClientOnScenarioDownload') { Get-ScheduledTask -TaskName $t -ErrorAction SilentlyContinue | Disable-ScheduledTask -ErrorAction SilentlyContinue | Out-Null } # Per-user settings, for everyone on the PC and for new accounts. Invoke-ForEachUserHive { param($root) $cdm = "$root\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" foreach ($n in 'SilentInstalledAppsEnabled', 'PreInstalledAppsEnabled', 'PreInstalledAppsEverEnabled', 'OemPreInstalledAppsEnabled', 'SystemPaneSuggestionsEnabled', 'SubscribedContent-338388Enabled') { Set-Reg $cdm $n 0 } Set-Reg "$root\Software\Policies\Microsoft\Windows\WindowsCopilot" 'TurnOffWindowsCopilot' 1 Set-Reg "$root\Software\Policies\Microsoft\Windows\WindowsAI" 'DisableAIDataAnalysis' 1 Set-Reg "$root\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" 'ShowCopilotButton' 0 Set-Reg "$root\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel" '{2cc5ca98-6485-489a-920e-b3e88a6ccce3}' 1 Set-Reg "$root\Software\Microsoft\Windows\CurrentVersion\GameDVR" 'AppCaptureEnabled' 0 Set-Reg "$root\System\GameConfigStore" 'GameDVR_Enabled' 0 } Write-Log 'Turned off suggested apps, Widgets, Recall, Copilot and Game Bar pop-ups (all users).' 'OK' } # ============================================================================= # MAIN # ============================================================================= try { Write-Host "" Write-Host " Nerdy Neighbor - Remove OEM and Windows bloat" -ForegroundColor Cyan Write-Host "" Write-Log "=== Run started on $env:COMPUTERNAME (user: $env:USERNAME) ===" $cs = Get-CimInstance -ClassName Win32_ComputerSystem Write-Log "This PC: $($cs.Manufacturer) $($cs.Model)" Write-Host "" Write-Host " This will remove:" -ForegroundColor White Write-Host " - the PC maker's preinstalled apps (HP / Dell / Lenovo / Samsung / Acer / Asus)" -ForegroundColor Gray Write-Host " - Xbox app, Weather, News, Clipchamp, Copilot, Teams, Solitaire and other extras" -ForegroundColor Gray Write-Host " and turn off suggested apps, Widgets, Recall and Copilot." -ForegroundColor Gray Write-Host " Kept: HP Smart, Photos, Media Player, Mail, Clock, Quick Assist, Office, Edge ..." -ForegroundColor Gray Write-Host " A restore point is made first." -ForegroundColor Gray Write-Host "" if ($env:NN_DEBLOAT -ne 'yes') { $isSystem = [Security.Principal.WindowsIdentity]::GetCurrent().IsSystem $canPrompt = [Environment]::UserInteractive -and -not $isSystem -and -not [Console]::IsInputRedirected if (-not $canPrompt) { Write-Log 'Nothing changed. To run without a prompt: $env:NN_DEBLOAT = ''yes''' 'WARN' return } $ans = Read-Host " Type YES to continue" if ($ans -notmatch '^\s*y(es)?\s*$') { Write-Log 'Cancelled - nothing changed.' 'WARN'; Write-Host ''; return } } New-NNRestorePoint Write-Log 'Removing Windows extras (Xbox, Weather, News, Copilot, Teams, ...)...' $removedAppx = Remove-AppxBloat Write-Log ('Removed {0} Windows/Store app(s).' -f $removedAppx.Count) 'OK' Set-WindowsSettings Write-Log "Removing $($cs.Manufacturer) software (can take 5-15 minutes)..." $startUtc = (Get-Date).ToUniversalTime() & { # RemoveBloat's code expects to carry on past errors. $ErrorActionPreference = 'Continue' $ProgressPreference = 'SilentlyContinue' ############################################################################ # BEGIN code from Andrew Taylor's RemoveBloat.ps1 (GPL-3.0), commit # ce39945d999568ee67aec9f7571250293fde9689 - its "Grab all Uninstall Strings" and # "Remove Manufacturer Bloat" sections, unchanged except where marked "NN:". ############################################################################ # Grab all Uninstall Strings # # # ############################################################################################################ write-output "Checking 32-bit System Registry" ##Search for 32-bit versions and list them $allstring = @() $path1 = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall" #Loop Through the apps if name has Adobe and NOT reader $32apps = Get-ChildItem -Path $path1 | Get-ItemProperty | Select-Object -Property DisplayName, UninstallString foreach ($32app in $32apps) { #Get uninstall string $string1 = $32app.uninstallstring #Check if it's an MSI install if ($string1 -match "^\s*(C:\\Windows\\System32\\)?msiexec(\.exe)?\s+\S*") { #MSI install, replace the I with an X and make it quiet $string2 = $string1 + " /quiet /norestart" $string2 = $string2 -replace "/I", "/X " #Create custom object with name and string $allstring += New-Object -TypeName PSObject -Property @{ Name = $32app.DisplayName String = $string2 } } else { #Exe installer, run straight path $string2 = $string1 $allstring += New-Object -TypeName PSObject -Property @{ Name = $32app.DisplayName String = $string2 } } } write-output "32-bit check complete" write-output "Checking 64-bit System registry" ##Search for 64-bit versions and list them $path2 = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" #Loop Through the apps if name has Adobe and NOT reader $64apps = Get-ChildItem -Path $path2 | Get-ItemProperty | Select-Object -Property DisplayName, UninstallString foreach ($64app in $64apps) { #Get uninstall string $string1 = $64app.uninstallstring #Check if it's an MSI install if ($string1 -match "^\s*(C:\\Windows\\System32\\)?msiexec(\.exe)?\s+\S*") { #MSI install, replace the I with an X and make it quiet $string2 = $string1 + " /quiet /norestart" $string2 = $string2 -replace "/I", "/X " #Uninstall with string2 params $allstring += New-Object -TypeName PSObject -Property @{ Name = $64app.DisplayName String = $string2 } } else { #Exe installer, run straight path $string2 = $string1 $allstring += New-Object -TypeName PSObject -Property @{ Name = $64app.DisplayName String = $string2 } } } write-output "64-bit checks complete" if ([System.Security.Principal.WindowsIdentity]::GetCurrent().Name -ne "NT AUTHORITY\SYSTEM") { ##USER write-output "Checking 32-bit User Registry" ##Search for 32-bit versions and list them $path1 = "HKCU:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall" ##Check if path exists if (Test-Path $path1) { #Loop Through the apps if name has Adobe and NOT reader $32apps = Get-ChildItem -Path $path1 | Get-ItemProperty | Select-Object -Property DisplayName, UninstallString foreach ($32app in $32apps) { #Get uninstall string $string1 = $32app.uninstallstring #Check if it's an MSI install if ($string1 -match "^\s*(C:\\Windows\\System32\\)?msiexec(\.exe)?\s+\S*") { #MSI install, replace the I with an X and make it quiet $string2 = $string1 + " /quiet /norestart" $string2 = $string2 -replace "/I", "/X " #Create custom object with name and string $allstring += New-Object -TypeName PSObject -Property @{ Name = $32app.DisplayName String = $string2 } } else { #Exe installer, run straight path $string2 = $string1 $allstring += New-Object -TypeName PSObject -Property @{ Name = $32app.DisplayName String = $string2 } } } } write-output "32-bit check complete" write-output "Checking 64-bit Use registry" ##Search for 64-bit versions and list them $path2 = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" #Loop Through the apps if name has Adobe and NOT reader $64apps = Get-ChildItem -Path $path2 | Get-ItemProperty | Select-Object -Property DisplayName, UninstallString foreach ($64app in $64apps) { #Get uninstall string $string1 = $64app.uninstallstring #Check if it's an MSI install if ($string1 -match "^\s*(C:\\Windows\\System32\\)?msiexec(\.exe)?\s+\S*") { #MSI install, replace the I with an X and make it quiet $string2 = $string1 + " /quiet /norestart" $string2 = $string2 -replace "/I", "/X " #Uninstall with string2 params $allstring += New-Object -TypeName PSObject -Property @{ Name = $64app.DisplayName String = $string2 } } else { #Exe installer, run straight path $string2 = $string1 $allstring += New-Object -TypeName PSObject -Property @{ Name = $64app.DisplayName String = $string2 } } } } function parseExeUninstall { param ( [string]$exeString ) $pattern = ' +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)' $exeString = $exeString.Trim() ## Unquoted path containing spaces (e.g. HP: c:\Program Files\HP\...\setup.exe), take everything up to the first .exe as the executable if (($exeString -notmatch '^"') -and ($exeString -match '^(?[^"]+?\.exe)(?:\s+(?.*))?$')) { $exeArgs = @() if ($matches['args']) { $exeArgs = $matches['args'].Trim() -split $pattern } return @($matches['exe']) + $exeArgs } $exeString = $exeString.Trim() ## Unquoted path containing spaces (e.g. HP: c:\Program Files\HP\...\setup.exe), take everything up to the first .exe as the executable if (($exeString -notmatch '^"') -and ($exeString -match '^(?[^"]+?\.exe)(?:\s+(?.*))?$')) { $exeArgs = @() if ($matches['args']) { $exeArgs = $matches['args'].Trim() -split $pattern } return @($matches['exe']) + $exeArgs } return $exeString -split $pattern } function UninstallAppFull { param ( [string]$appName ) # Get a list of installed applications from Programs and Features $installedApps = Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*, HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object { $null -ne $_.DisplayName } | Select-Object DisplayName, UninstallString, QuietUninstallString if ( [System.Security.Principal.WindowsIdentity]::GetCurrent().Name -ne 'NT AUTHORITY\SYSTEM') { $userInstalledApps = Get-ItemProperty HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object { $null -ne $_.DisplayName } | Select-Object DisplayName, UninstallString, QuietUninstallString } # Wrapping the two arrays in @( ) forces them to resolve as arrays, including if they're NULL (such as if running in the system context and $userInstalledApps wasn't initialized above). $allInstalledApps = @($installedApps) + @($userInstalledApps) | Where-Object { $_.DisplayName -eq "$appName" } # Loop through the list of installed applications and uninstall them foreach ($app in $allInstalledApps) { $uninstallString = $app.UninstallString $displayName = $app.DisplayName Write-Output "Calling Uninstaller for: $displayName" if ($uninstallString -match "^\s*(C:\\Windows\\System32\\)?msiexec(\.exe)?\s+\S*") { Write-Output "MSI Uninstall detected" #MSI install, replace the I with an X and make it quiet $uninstallString -match '(?{.*})' | Out-Null # Out-Null avoids "True" being output without context. $GUID = $matches['content'] $uninstallArgs = @( '/X', $GUID, '/quiet', '/norestart', '/qn' ) $uninstaller = "msiexec.exe" Write-Output "Uninstall Arguments: $uninstallArgs" # To refactorize back to a single uninstall call, remove here to the next comment. From here... try { ##Capture the exit code so failures are visible in the transcript $proc = Start-Process $uninstaller -ArgumentList $uninstallArgs -wait -PassThru Write-Output "MSI Uninstaller for $displayName exited with code: $($proc.ExitCode)" } catch { Write-Output "Failed to call MSI Uninstaller for: $displayName" Write-Output "UninstallArgs: $uninstallArgs" Write-Output "Error thrown: $($_.Exception.Message)" } # ... to here. } else { Write-Output "EXE Uninstall detected" #Exe installer, run straight path ##Prefer QuietUninstallString when the app registers one $exeString = $uninstallString if ($app.QuietUninstallString) { $exeString = $app.QuietUninstallString Write-Output "QuietUninstallString found, using it instead" } Write-Output "Retrieved Uninstall String: $exeString" ## @( ) forces an array so a bare exe path is not indexed character-by-character $parsedString = @(parseExeUninstall -exeString $exeString) $uninstallArgs = @($parsedString | Select-Object -Skip 1) $uninstaller = $parsedString[0].Trim('"') if (-not $app.QuietUninstallString) { ## No quiet string registered, so add the correct silent switch for known uninstaller types if (($uninstallArgs -match '/uninstall') -and -not ($uninstallArgs -match '/quiet')) { ## Burn bundle (e.g. Dell SupportAssist Remediation / OS Recovery Plugin) $uninstallArgs += '/quiet' } elseif ($uninstaller -match 'SupportAssistUninstaller\.exe$') { ## InstallShield-wrapped SupportAssist agent uninstaller if ($uninstallArgs -notcontains '/arp') { $uninstallArgs += '/arp' } $uninstallArgs += @('/S', '/v/qn') } elseif (($uninstaller -match '(uninst|uninstall)\.exe$') -and ($uninstallArgs -notcontains '/S')) { ## NSIS uninstaller $uninstallArgs += '/S' } } # To refactorize back to a single uninstall call, remove here to the next comment. From here... try { $exeStartParams = @{ FilePath = $uninstaller; Wait = $true; PassThru = $true } if ($uninstallArgs.Count -gt 0) { $exeStartParams['ArgumentList'] = $uninstallArgs } $proc = Start-Process @exeStartParams Write-Output "EXE Uninstaller for $displayName exited with code: $($proc.ExitCode)" } catch { Write-Output "Failed to call EXE Uninstaller for: $displayName" Write-Output "Uninstaller: $uninstaller" Write-Output "UninstallArgs: $uninstallArgs" Write-Output "Error thrown: $($_.Exception.Message)" } # ... to here. } <# Remove this line and it's accompanying end cap to make this section live. try { Start-Process $uninstaller -ArgumentList $uninstallArgs Write-Output "Successfully called uninstaller for: $displayName." } catch { Write-Output "Failed to call Uninstaller for: $displayName" Write-Output "Uninstaller: $uninstaller" Write-Output "UninstallArgs: $uninstallArgs" Write-Output "Error thrown: $($_.Exception.Message)" } I'm the end cap! Don't forget to remove me, if you remove my parent! #> } } function Test-ProcessCritical { # $true if any of the given processes is marked CRITICAL - terminating one bugchecks Windows # (0xEF CRITICAL_PROCESS_DIED). If we can't determine it, return $true so the caller does NOT # kill it. Accepts zero, one, or many processes (e.g. several instances sharing the same name). [CmdletBinding()] param([System.Diagnostics.Process[]]$Process) if (-not ([System.Management.Automation.PSTypeName]'CwApi.ProcCheck').Type) { Add-Type -Language CSharp -TypeDefinition @" using System; using System.Runtime.InteropServices; namespace CwApi { public static class ProcCheck { [DllImport("kernel32.dll", SetLastError = true)] public static extern bool IsProcessCritical(IntPtr hProcess, out bool Critical); } } "@ } if (-not $Process) { return $false # nothing matched, so there is nothing critical to protect } foreach ($proc in $Process) { try { $crit = $false if ([CwApi.ProcCheck]::IsProcessCritical($proc.Handle, [ref]$crit)) { if ($crit) { return $true } } else { return $true # API call failed - be safe, treat as critical } } catch { return $true # can't open/query the process - be safe, do NOT kill it } } return $false } ############################################################################################################ # Remove Manufacturer Bloat # # # ############################################################################################################ ##Check Manufacturer write-output "Detecting Manufacturer" $details = Get-CimInstance -ClassName Win32_ComputerSystem $manufacturer = $details.Manufacturer if ($manufacturer -like "*HP*") { write-output "HP detected" #Remove HP bloat ##HP Specific $UninstallPrograms = @( "Poly Lens" "HP Client Security Manager" "HP Notifications" "HP Security Update Service" "HP System Default Settings" "HP Wolf Security" "HP Wolf Security - Console" "HP Wolf Security Application Support for Sure Sense" "HP Wolf Security Application Support for Windows" "HP Wolf Security Application Support for Chrome 122.0.6261.139" "AD2F1837.HPPCHardwareDiagnosticsWindows" "AD2F1837.HPPowerManager" "AD2F1837.HPPrivacySettings" "AD2F1837.HPQuickDrop" "AD2F1837.HPSupportAssistant" "AD2F1837.HPSystemInformation" "AD2F1837.myHP" "RealtekSemiconductorCorp.HPAudioControl", "HP Sure Recover", "HP Sure Run Module" "RealtekSemiconductorCorp.HPAudioControl_2.39.280.0_x64__dt26b99r8h8gj" "Windows Driver Package - HP Inc. sselam_4_4_2_453 AntiVirus (11/01/2022 4.4.2.453)" "HP Insights" "HP Insights Analytics" "HP Insights Analytics Service" "HP Insights Analytics - Dependencies" "HP Performance Advisor" "HP Presence Video" "HP Audio Control" "HP Documentation" "AD2F1837.HPAudioControl" "HP Connect Optimizer" ) $UninstallPrograms = $UninstallPrograms | Where-Object { $appstoignore -notcontains $_ } #$HPidentifier = "AD2F1837" #$ProvisionedPackages = Get-AppxProvisionedPackage -Online | Where-Object {(($UninstallPrograms -contains $_.DisplayName) -or (($_.DisplayName -like "*$HPidentifier"))-and ($_.DisplayName -notin $WhitelistedApps))} #$InstalledPackages = Get-AppxPackage -AllUsers | Where-Object {(($UninstallPrograms -contains $_.Name) -or (($_.Name -like "^$HPidentifier"))-and ($_.Name -notin $WhitelistedApps))} $InstalledPrograms = $allstring | Where-Object { $UninstallPrograms -contains $_.Name } foreach ($app in $UninstallPrograms) { if (Get-AppxProvisionedPackage -Online | Where-Object DisplayName -like $app -ErrorAction SilentlyContinue) { Get-AppxProvisionedPackage -Online | Where-Object DisplayName -like $app | Remove-AppxProvisionedPackage -Online write-output "Removed provisioned package for $app." } else { write-output "Provisioned package for $app not found." } if (Get-AppxPackage -allusers -Name $app -ErrorAction SilentlyContinue) { Get-AppxPackage -allusers -Name $app | Remove-AppxPackage -AllUsers write-output "Removed $app." } else { write-output "$app not found." } if (Get-Package -scope allusers -Name $app -ErrorAction SilentlyContinue) { Get-Package -scope allusers -Name $app | Uninstall-Package -scope AllUsers write-output "Removed $app." } else { write-output "$app not found." } UninstallAppFull -appName $app } ##Belt and braces, remove via CIM too #foreach ($program in $UninstallPrograms) { # Get-CimInstance -Classname Win32_Product | Where-Object Name -Match $program | Invoke-CimMethod -MethodName UnInstall #} #Remove HP Documentation if it exists if (test-path -Path "C:\Program Files\HP\Documentation\Doc_uninstall.cmd") { Start-Process -FilePath "C:\Program Files\HP\Documentation\Doc_uninstall.cmd" -Wait -passthru -NoNewWindow } ##Remove HP Connect Optimizer if setup.exe exists if (test-path -Path 'C:\Program Files (x86)\InstallShield Installation Information\{6468C4A5-E47E-405F-B675-A70A70983EA6}\setup.exe') { ## NN: answer file is embedded ($HPConnOptIss) and written to an admin-only folder ## instead of being downloaded into C:\Windows\Temp. $issDir = New-AdminOnlyDir 'hpconnopt' $issFile = Join-Path $issDir 'HPConnOpt.iss' Set-Content -Path $issFile -Value $HPConnOptIss -Encoding ASCII &'C:\Program Files (x86)\InstallShield Installation Information\{6468C4A5-E47E-405F-B675-A70A70983EA6}\setup.exe' @('-s', "-f1$issFile") Remove-Item -Path $issDir -Recurse -Force -ErrorAction SilentlyContinue } ##Remove HP Data Science Stack Manager if (test-path -Path 'C:\Program Files\HP\Z By HP Data Science Stack Manager\Uninstall Z by HP Data Science Stack Manager.exe') { &'C:\Program Files\HP\Z By HP Data Science Stack Manager\Uninstall Z by HP Data Science Stack Manager.exe' @('/allusers', '/S') } ##Remove other crap if (Test-Path -Path "C:\Program Files (x86)\HP\Shared" -PathType Container) { Remove-Item -Path "C:\Program Files (x86)\HP\Shared" -Recurse -Force } if (Test-Path -Path "C:\Program Files (x86)\Online Services" -PathType Container) { Remove-Item -Path "C:\Program Files (x86)\Online Services" -Recurse -Force } if (Test-Path -Path "C:\ProgramData\HP\TCO" -PathType Container) { Remove-Item -Path "C:\ProgramData\HP\TCO" -Recurse -Force } if (Test-Path -Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Amazon.com.lnk" -PathType Leaf) { Remove-Item -Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Amazon.com.lnk" -Force } if (Test-Path -Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Angebote.lnk" -PathType Leaf) { Remove-Item -Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Angebote.lnk" -Force } if (Test-Path -Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\TCO Certified.lnk" -PathType Leaf) { Remove-Item -Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\TCO Certified.lnk" -Force } if (Test-Path -Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Booking.com.lnk" -PathType Leaf) { Remove-Item -Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Booking.com.lnk" -Force } if (Test-Path -Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Adobe offers.lnk" -PathType Leaf) { Remove-Item -Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Adobe offers.lnk" -Force } if (Test-Path -Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Miro Offer.lnk" -PathType Leaf) { Remove-Item -Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Miro offer.lnk" -Force } ##Remove Wolf Security #Get-CimInstance -ClassName Win32_Product | Where-Object { $_.Name -eq 'HP Wolf Security' } | Invoke-CimMethod -MethodName Uninstall #Get-CimInstance -ClassName Win32_Product | Where-Object { $_.Name -eq 'HP Wolf Security - Console' } | Invoke-CimMethod -MethodName Uninstall #Get-CimInstance -ClassName Win32_Product | Where-Object { $_.Name -eq 'HP Security Update Service' } | Invoke-CimMethod -MethodName Uninstall # Main execution Write-output "Starting HP security package uninstallation process" # Define packages and criteria $packagePatterns = @( @{ Name = "HP Client Security Manager"; MinVersion = "10.0.0" }, @{ Name = "HP Wolf Security(?!.*Console)" }, @{ Name = "HP Wolf Security.*Console" }, @{ Name = "HP Security Update Service" } ) # Process each package pattern foreach ($pattern in $packagePatterns) { $patternName = $pattern.Name $minVersion = $pattern.MinVersion Write-Output "Checking for packages matching pattern: $patternName" # Search for matching packages in the registry $matchingPackages = @() # Check in 32-bit and 64-bit registry locations $registryPaths = @( "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*", "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" ) foreach ($registryPath in $registryPaths) { $packages = Get-ItemProperty -Path $registryPath -ErrorAction SilentlyContinue | Where-Object { $_.DisplayName -match [regex]::Escape($patternName) } # Filter by minimum version if specified if ($minVersion -and $packages) { $packages = $packages | Where-Object { if ($_.DisplayVersion) { try { [version]$_.DisplayVersion -ge [version]$minVersion } catch { # If version comparison fails, include it anyway for safety $true } } else { # If no version information, include it for safety $true } } } $matchingPackages += $packages } if ($matchingPackages.Count -eq 0) { Write-Output "No packages found matching pattern: $patternName" continue } Write-Output "Found $($matchingPackages.Count) package(s) matching pattern: $patternName" # Process each matching package foreach ($package in $matchingPackages) { $displayName = $package.DisplayName $uninstallString = $package.UninstallString $quietUninstallString = $package.QuietUninstallString $version = $package.DisplayVersion Write-Output "Attempting to uninstall: $displayName (Version: $version)" # Try to use the UninstallAppFull function first Write-Output "Trying to uninstall via UninstallAppFull..." UninstallAppFull -appName $displayName ##Skip the fallback if UninstallAppFull already removed the app if (-not (Test-Path $package.PSPath)) { Write-Output "$displayName removed by UninstallAppFull, skipping fallback" continue } # If UninstallAppFull doesn't work, fall back to direct uninstallation # Check if uninstall string exists and attempt uninstall if ($quietUninstallString) { Write-Output "Using quiet uninstall string: $quietUninstallString" try { if ($quietUninstallString -match "msiexec") { # For MSI-based uninstalls, add /quiet $uninstallCommand = $quietUninstallString + " /quiet" Start-Process "cmd.exe" -ArgumentList "/c $uninstallCommand" -Wait -NoNewWindow } else { # For EXE-based uninstalls ##Use parseExeUninstall so quoted paths containing spaces parse correctly $parsedQuiet = @(parseExeUninstall -exeString $quietUninstallString) $uninstallExe = $parsedQuiet[0].Trim('"') $uninstallArgs = @($parsedQuiet | Select-Object -Skip 1) $quietStartParams = @{ FilePath = $uninstallExe; Wait = $true; NoNewWindow = $true } if ($uninstallArgs.Count -gt 0) { $quietStartParams['ArgumentList'] = $uninstallArgs } Start-Process @quietStartParams } Write-Output "Quiet uninstall completed for: $displayName" } catch { Write-Output "Error during quiet uninstall: $_" } } elseif ($uninstallString) { Write-Output "Using standard uninstall string: $uninstallString" try { if ($uninstallString -match "msiexec") { # For MSI-based uninstalls, add /quiet if ($uninstallString -match "/I{") { # Change /I to /X for uninstall if needed $uninstallString = $uninstallString -replace "/I", "/X" } $uninstallCommand = $uninstallString + " /quiet" Start-Process "cmd.exe" -ArgumentList "/c $uninstallCommand" -Wait -NoNewWindow } else { # For EXE-based uninstalls ##Use parseExeUninstall so quoted paths containing spaces parse correctly $parsedStandard = @(parseExeUninstall -exeString $uninstallString) $uninstallExe = $parsedStandard[0].Trim('"') $uninstallArgs = @($parsedStandard | Select-Object -Skip 1) # Add silent parameters for common installers if ($uninstallString -match "uninstall.exe|uninst.exe|setup.exe|installer.exe") { $uninstallArgs += @("/S", "/silent", "/quiet", "/uninstall") } $standardStartParams = @{ FilePath = $uninstallExe; Wait = $true; NoNewWindow = $true } if ($uninstallArgs.Count -gt 0) { $standardStartParams['ArgumentList'] = $uninstallArgs } Start-Process @standardStartParams } Write-Output "Standard uninstall completed for: $displayName" } catch { Write-Output "Error during standard uninstall: $_" } } else { Write-Output "No uninstall string found for: $displayName" } } } ##Use Winget to catch Wolf Security ## Write-Output "Attempting to uninstall HP Wolf Security via Winget" ## $ResolveWingetPath = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe" ## if ($ResolveWingetPath){ ## $WingetPath = $ResolveWingetPath[-1].Path ## } ## $Winget = $WingetPath + "\winget.exe" ## &$winget install --id "$appid" --silent --force --accept-package-agreements --accept-source-agreements --exact | out-null ## write-output "Removed HP bloat" } if ($manufacturer -like "*Dell*") { write-output "Dell detected" #Remove Dell bloat ##Dell $UninstallPrograms = @( "Dell Power Manager" "DellOptimizerUI" "Dell SupportAssist OS Recovery" "Dell SupportAssist" "DellInc.PartnerPromo" "DellInc.DellOptimizer" "DellInc.DellCommandUpdate" "DellInc.DellPowerManager" "DellInc.DellDigitalDelivery" "DellInc.DellSupportAssistforPCs" "Dell.SupportAssistforPCs" "DellInc.PartnerPromo" "Dell Command | Update" "Dell Command | Update for Windows Universal" "Dell Command | Update for Windows 10" "Dell Command | Power Manager" "Dell Digital Delivery Service" "Dell Digital Delivery" "Dell Peripheral Manager" "Dell Power Manager Service" "Dell SupportAssist Remediation" "SupportAssist Recovery Assistant" "Dell SupportAssist OS Recovery Plugin for Dell Update" "Dell SupportAssistAgent" ##"Dell Update - SupportAssist Update Plugin" "Dell Core Services" "Dell Pair" "Dell Display Manager 2.0" "Dell Display Manager 2.1" "Dell Display Manager 2.2" "DellInc.PartnerPromo" "Dell Trusted Device" ##This is handled further down ##"Dell Optimizer" "Dell AppCore (Optimizer Console)" "Dell AppCore" "Dell.Digital.Delivery-64Bit" ) ##Stop Running Processes $processnames = @( "DellEnterpriseClientFrameworkSubAgent", "DellOptimizer", "DellOptimizer.Systray", "DellPair", "DellPairService", "DellSupportAssistRemediationServiceInstaller", "DellUpdateSupportAssistPlugin", "SupportAssistAgent", "SupportAssistClientUI" ) foreach ($process in $processnames) { write-output "Checking for Process $process" if (Test-ProcessCritical -Process (Get-Process -Name $process -ErrorAction SilentlyContinue)) { write-output "Process $process is critical and cannot be stopped." } else { write-output "Stopping Process $process" Get-Process -Name $process | Stop-Process -Force write-output "Process $process Stopped" } } ##Stop SupportAssist services so their files are not locked during uninstall Get-Service | Where-Object { $_.DisplayName -like "*SupportAssist*" -and $_.Status -eq "Running" } | ForEach-Object { write-output "Stopping Service $($_.Name)" Stop-Service -Name $_.Name -Force -ErrorAction SilentlyContinue } ##Run the quiet uninstalls for the SupportAssist bundles before the generic loops so a ##partially-run bundle uninstaller cannot block the correct quiet command later ##Dell Dell SupportAssist Remediation $dellSA = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | Get-ItemProperty | Where-Object { $_.DisplayName -match "Dell SupportAssist Remediation" } | Select-Object -Property QuietUninstallString ForEach ($sa in $dellSA) { If ($sa.QuietUninstallString) { try { write-output "Removing Dell SupportAssist Remediation using its quiet uninstall string" cmd.exe /c $sa.QuietUninstallString } catch { Write-Warning "Failed to uninstall Dell Support Assist Remediation" } } } ##Dell Dell SupportAssist OS Recovery Plugin for Dell Update $dellSA = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | Get-ItemProperty | Where-Object { $_.DisplayName -match "Dell SupportAssist OS Recovery Plugin for Dell Update" } | Select-Object -Property QuietUninstallString ForEach ($sa in $dellSA) { If ($sa.QuietUninstallString) { try { write-output "Removing Dell SupportAssist OS Recovery Plugin for Dell Update using its quiet uninstall string" cmd.exe /c $sa.QuietUninstallString } catch { Write-Warning "Failed to uninstall Dell Support OS Recovery Plugin" } } } $UninstallPrograms = $UninstallPrograms | Where-Object { $appstoignore -notcontains $_ } foreach ($app in $UninstallPrograms) { if (Get-AppxProvisionedPackage -Online | Where-Object DisplayName -like $app -ErrorAction SilentlyContinue) { Get-AppxProvisionedPackage -Online | Where-Object DisplayName -like $app | Remove-AppxProvisionedPackage -Online write-output "Removed provisioned package for $app." } else { write-output "Provisioned package for $app not found." } if (Get-AppxPackage -allusers -Name $app -ErrorAction SilentlyContinue) { Get-AppxPackage -allusers -Name $app | Remove-AppxPackage -AllUsers write-output "Removed $app." } else { write-output "$app not found." } UninstallAppFull -appName $app } # Process each package pattern foreach ($pattern in $uninstallPrograms) { $patternName = $pattern $minVersion = $pattern.MinVersion Write-Output "Checking for packages matching pattern: $patternName" # Search for matching packages in the registry $matchingPackages = @() # Check in 32-bit and 64-bit registry locations $registryPaths = @( "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*", "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" ) foreach ($registryPath in $registryPaths) { $packages = Get-ItemProperty -Path $registryPath -ErrorAction SilentlyContinue | Where-Object { $_.DisplayName -match [regex]::Escape($patternName) } # Filter by minimum version if specified if ($minVersion -and $packages) { $packages = $packages | Where-Object { if ($_.DisplayVersion) { try { [version]$_.DisplayVersion -ge [version]$minVersion } catch { # If version comparison fails, include it anyway for safety $true } } else { # If no version information, include it for safety $true } } } $matchingPackages += $packages } if ($matchingPackages.Count -eq 0) { Write-Output "No packages found matching pattern: $patternName" continue } Write-Output "Found $($matchingPackages.Count) package(s) matching pattern: $patternName" # Process each matching package foreach ($package in $matchingPackages) { $displayName = $package.DisplayName $uninstallString = $package.UninstallString $quietUninstallString = $package.QuietUninstallString $version = $package.DisplayVersion Write-Output "Attempting to uninstall: $displayName (Version: $version)" # Try to use the UninstallAppFull function first Write-Output "Trying to uninstall via UninstallAppFull..." UninstallAppFull -appName $displayName ##Skip the fallback if UninstallAppFull already removed the app if (-not (Test-Path $package.PSPath)) { Write-Output "$displayName removed by UninstallAppFull, skipping fallback" continue } # If UninstallAppFull doesn't work, fall back to direct uninstallation # Check if uninstall string exists and attempt uninstall if ($quietUninstallString) { Write-Output "Using quiet uninstall string: $quietUninstallString" try { if ($quietUninstallString -match "msiexec") { # For MSI-based uninstalls, add /quiet $uninstallCommand = $quietUninstallString + " /quiet" Start-Process "cmd.exe" -ArgumentList "/c $uninstallCommand" -Wait -NoNewWindow } else { # For EXE-based uninstalls ##Use parseExeUninstall so quoted paths containing spaces parse correctly $parsedQuiet = @(parseExeUninstall -exeString $quietUninstallString) $uninstallExe = $parsedQuiet[0].Trim('"') $uninstallArgs = @($parsedQuiet | Select-Object -Skip 1) $quietStartParams = @{ FilePath = $uninstallExe; Wait = $true; NoNewWindow = $true } if ($uninstallArgs.Count -gt 0) { $quietStartParams['ArgumentList'] = $uninstallArgs } Start-Process @quietStartParams } Write-Output "Quiet uninstall completed for: $displayName" } catch { Write-Output "Error during quiet uninstall: $_" } } elseif ($uninstallString) { Write-Output "Using standard uninstall string: $uninstallString" try { if ($uninstallString -match "msiexec") { # For MSI-based uninstalls, add /quiet if ($uninstallString -match "/I{") { # Change /I to /X for uninstall if needed $uninstallString = $uninstallString -replace "/I", "/X" } $uninstallCommand = $uninstallString + " /quiet" Start-Process "cmd.exe" -ArgumentList "/c $uninstallCommand" -Wait -NoNewWindow } else { # For EXE-based uninstalls ##Use parseExeUninstall so quoted paths containing spaces parse correctly $parsedStandard = @(parseExeUninstall -exeString $uninstallString) $uninstallExe = $parsedStandard[0].Trim('"') $uninstallArgs = @($parsedStandard | Select-Object -Skip 1) # Add silent parameters for common installers if ($uninstallString -match "uninstall.exe|uninst.exe|setup.exe|installer.exe") { $uninstallArgs += @("/S", "/silent", "/quiet", "/uninstall") } $standardStartParams = @{ FilePath = $uninstallExe; Wait = $true; NoNewWindow = $true } if ($uninstallArgs.Count -gt 0) { $standardStartParams['ArgumentList'] = $uninstallArgs } Start-Process @standardStartParams } Write-Output "Standard uninstall completed for: $displayName" } catch { Write-Output "Error during standard uninstall: $_" } } else { Write-Output "No uninstall string found for: $displayName" } } } ##Belt and braces, remove via CIM too #foreach ($program in $UninstallPrograms) { # write-output "Removing $program" # Get-CimInstance -Query "SELECT * FROM Win32_Product WHERE name = '$program'" | Invoke-CimMethod -MethodName Uninstall #} ##Manual Removals ##Dell Optimizer Core $dellSA = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | Get-ItemProperty | Where-Object { $_.DisplayName -like "Dell*Optimizer*Core" } | Select-Object -Property UninstallString ForEach ($sa in $dellSA) { If ($sa.UninstallString) { try { write-output "Removing Dell Optimizer Core using its uninstall string with -silent" cmd.exe /c $sa.UninstallString -silent } catch { Write-Warning "Failed to uninstall Dell Optimizer" } } } ##Dell Optimizer $dellSA = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | Get-ItemProperty | Where-Object { $_.DisplayName -like "Dell*Optimizer" -and $_.UninstallString -notmatch "msiexec" -and $_.UninstallString -notmatch "msiexec" } | Select-Object -Property UninstallString ForEach ($sa in $dellSA) { If ($sa.UninstallString) { try { write-output "Removing Dell Optimizer using its uninstall string with -silent" cmd.exe /c $sa.UninstallString -silent } catch { Write-Warning "Failed to uninstall Dell Optimizer" } } } ##Dell Display Manager $dellSA = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | Get-ItemProperty | Where-Object { $_.DisplayName -like "Dell*Display*Manager*" } | Select-Object -Property UninstallString ForEach ($sa in $dellSA) { If ($sa.UninstallString) { try { write-output "Removing Dell Display Manager using its uninstall string with /S" cmd.exe /c $sa.UninstallString /S } catch { Write-Warning "Failed to uninstall Dell Display Manager" } } } ##Dell Peripheral Manager try { write-output "Attempting Dell Peripheral Manager uninstall (if present)" start-process c:\windows\system32\cmd.exe '/c "C:\Program Files\Dell\Dell Peripheral Manager\Uninstall.exe" /S' } catch { Write-Warning "Failed to uninstall Dell Peripheral Manager" } ##Dell Pair try { write-output "Attempting Dell Pair uninstall (if present)" start-process c:\windows\system32\cmd.exe '/c "C:\Program Files\Dell\Dell Pair\Uninstall.exe" /S' } catch { Write-Warning "Failed to uninstall Dell Pair" } ##Dell Update Assist Plugin try { write-output "Attempting Dell Update SupportAssist Plugin uninstall (if present)" start-process c:\windows\system32\cmd.exe '/c "C:\ProgramData\Package Cache\{0a5aa116-8736-4571-b49d-739020affb16}\DellUpdateSupportAssistPlugin.exe" /uninstall /quiet' } catch { Write-Warning "Failed to uninstall Dell Update Assist Plugin" } } if ($manufacturer -like "Lenovo") { write-output "Lenovo detected" ##Lenovo Specific # Function to uninstall applications with .exe uninstall strings function UninstallApp { param ( [string]$appName ) # Get a list of installed applications from Programs and Features $installedApps = Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*, HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object { $_.DisplayName -like "*$appName*" } # Loop through the list of installed applications and uninstall them foreach ($app in $installedApps) { $uninstallString = $app.UninstallString $displayName = $app.DisplayName write-output "Uninstalling: $displayName" Start-Process $uninstallString -ArgumentList "/VERYSILENT" -Wait write-output "Uninstalled: $displayName" } } ##Stop Running Processes $processnames = @( "SmartAppearanceSVC.exe" "UDClientService.exe" "ModuleCoreService.exe" "ProtectedModuleHost.exe" "*lenovo*" "FaceBeautify.exe" "McCSPServiceHost.exe" "mcapexe.exe" "MfeAVSvc.exe" "mcshield.exe" "Ammbkproc.exe" "AIMeetingManager.exe" "DADUpdater.exe" "CommercialVantage.exe" "lenovo ainow.exe" "lenovo ainow helper.exe" "lenovo ainow service.exe" "lenovo ainow utility.exe" "lenovo ainow mini.exe" "lenovo ainow oobe.exe" "lenovo ainow safetychecker.exe" "lenovo ainow launcher.exe" "lenovoainow.exe" ) foreach ($process in $processnames) { write-output "Checking for Process $process" if (Test-ProcessCritical -Process (Get-Process -Name $process -ErrorAction SilentlyContinue)) { write-output "Process $process is critical and cannot be stopped." } else { write-output "Stopping Process $process" Get-Process -Name $process | Stop-Process -Force write-output "Process $process Stopped" } } $UninstallPrograms = @( "E046963F.AIMeetingManager" "E0469640.SmartAppearance" "MirametrixInc.GlancebyMirametrix" "E046963F.LenovoCompanion" "E0469640.LenovoUtility" "E0469640.LenovoSmartCommunication" "E046963F.LenovoSettingsforEnterprise" "E046963F.cameraSettings" "4505Fortemedia.FMAPOControl2_2.1.37.0_x64__4pejv7q2gmsnr" "ElevocTechnologyCo.Ltd.SmartMicrophoneSettings_1.1.49.0_x64__ttaqwwhyt5s6t" "Lenovo User Guide" "TrackPoint Quick Menu" "E0469640.TrackPointQuickMenu" "Lenovo AI Now" "Lenovo Subscription Marketplace" ) $UninstallPrograms = $UninstallPrograms | Where-Object { $appstoignore -notcontains $_ } $InstalledPrograms = $allstring | Where-Object { (($_.Name -in $UninstallPrograms)) } foreach ($app in $UninstallPrograms) { if (Get-AppxProvisionedPackage -Online | Where-Object DisplayName -like $app -ErrorAction SilentlyContinue) { Get-AppxProvisionedPackage -Online | Where-Object DisplayName -like $app | Remove-AppxProvisionedPackage -Online write-output "Removed provisioned package for $app." } else { write-output "Provisioned package for $app not found." } if (Get-AppxPackage -allusers -Name $app -ErrorAction SilentlyContinue) { Get-AppxPackage -allusers -Name $app | Remove-AppxPackage -AllUsers write-output "Removed $app." } else { write-output "$app not found." } UninstallAppFull -appName $app } ##Belt and braces, remove via CIM too #foreach ($program in $UninstallPrograms) { # Get-CimInstance -Classname Win32_Product | Where-Object Name -Match $program | Invoke-CimMethod -MethodName UnInstall #} # Get Lenovo Vantage service uninstall string to uninstall service $lvs = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*", "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" | Where-Object DisplayName -eq "Lenovo Vantage Service" if (!([string]::IsNullOrEmpty($lvs.QuietUninstallString))) { $uninstall = "cmd /c " + $lvs.QuietUninstallString write-output $uninstall Invoke-Expression $uninstall } # Uninstall Lenovo Smart #UninstallApp -appName "Lenovo Smart" $path2 = "C:\Program Files (x86)\Lenovo\Smart Storage\SmartStorageUnInstall.exe" $params = "/SILENT" if (test-path -Path $path2) { Start-Process -FilePath $path2 -ArgumentList $params -Wait } # Uninstall Ai Meeting Manager Service UninstallApp -appName "Ai Meeting Manager" # Uninstall ImController service ##Check if exists $path = "c:\windows\system32\ImController.InfInstaller.exe" if (Test-Path $path) { write-output "ImController.InfInstaller.exe exists" $uninstall = "cmd /c " + $path + " -uninstall" write-output $uninstall Invoke-Expression $uninstall } else { write-output "ImController.InfInstaller.exe does not exist" } ##Invoke-Expression -Command 'cmd.exe /c "c:\windows\system32\ImController.InfInstaller.exe" -uninstall' # Remove vantage associated registry keys Remove-Item 'HKLM:\SOFTWARE\Policies\Lenovo\E046963F.LenovoCompanion_k1h2ywk1493x8' -Recurse -ErrorAction SilentlyContinue Remove-Item 'HKLM:\SOFTWARE\Policies\Lenovo\ImController' -Recurse -ErrorAction SilentlyContinue Remove-Item 'HKLM:\SOFTWARE\Policies\Lenovo\Lenovo Vantage' -Recurse -ErrorAction SilentlyContinue #Remove-Item 'HKLM:\SOFTWARE\Policies\Lenovo\Commercial Vantage' -Recurse -ErrorAction SilentlyContinue # Uninstall AI Meeting Manager Service $path = 'C:\Program Files\Lenovo\Ai Meeting Manager Service\unins000.exe' $params = "/SILENT" if (test-path -Path $path) { Start-Process -FilePath $path -ArgumentList $params -Wait } # Uninstall Lenovo Now $path = 'C:\Program Files (x86)\Lenovo\LenovoNow\unins000.exe' $params = "/SILENT" if (test-path -Path $path) { Start-Process -FilePath $path -ArgumentList $params -Wait } # Uninstall Lenovo AI Now $path = "C:\Program Files\Lenovo\Lenovo AI Now\Lenovo AINow Uninstall.exe" $params = "SlientUninstall" if (test-path -Path $path) { Start-Process -FilePath $path -ArgumentList $params -Wait } # Uninstall Lenovo Qira $path = "C:\Program Files\Lenovo\Lenovo Qira\Lenovo Qira Uninstall.exe" $params = "SlientUninstall" if (test-path -Path $path) { Start-Process -FilePath $path -ArgumentList $params -Wait } #First check if Commercial vantage is installed $vantagePackage = Get-AppxPackage -Name E046963F.LenovoSettingsforEnterprise -AllUsers -ErrorAction silentlyContinue if ($vantagePackage) { # Uninstall Lenovo Vantage $pathname = (Get-ChildItem -Path "C:\Program Files (x86)\Lenovo\VantageService").name $path = "C:\Program Files (x86)\Lenovo\VantageService\$pathname\Uninstall.exe" $params = '/SILENT' if (test-path -Path $path) { Start-Process -FilePath $path -ArgumentList $params -Wait } } # Uninstall Lenovo Smart Meeting $path = 'C:\Program Files\Lenovo\Lenovo Smart Meeting Components\unins000.exe' $params = "/SILENT" if (test-path -Path $path) { Start-Process -FilePath $path -ArgumentList $params -Wait } # Uninstall Lenovo Smart Connect $path = 'C:\Program Files\Lenovo\Ready For Assistant\uninstall.exe' $params = "/S" if (test-path -Path $path) { Start-Process -FilePath $path -ArgumentList $params -Wait } ##Uninstall Smart Appearance $path = 'C:\Program Files\Lenovo\Lenovo Smart Appearance Components\unins000.exe' $params = '/SILENT' if (test-path -Path $path) { try { Start-Process -FilePath $path -ArgumentList $params -Wait } catch { Write-Warning "Failed to start the process" } } $lenovowelcome = "C:\Program Files (x86)\Lenovo\LenovoWelcome\x86" if (Test-Path $lenovowelcome) { $uninstallScript = Join-Path $lenovowelcome "uninstall.ps1" if (Test-Path $uninstallScript) { try { & $uninstallScript *>&1 | ForEach-Object { Write-Output "[LenovoWelcome] $_" } } catch { Write-Output "LenovoWelcome uninstall warning: $($_.Exception.Message)" } } Write-Output "All LenovoWelcome components have been uninstalled." } $lenovonow = "C:\Program Files (x86)\Lenovo\LenovoNow\x86" if (Test-Path $lenovonow) { $uninstallScript = Join-Path $lenovonow "uninstall.ps1" if (Test-Path $uninstallScript) { try { & $uninstallScript *>&1 | ForEach-Object { Write-Output "[LenovoNow] $_" } } catch { Write-Output "LenovoNow uninstall warning: $($_.Exception.Message)" } } Write-Output "All LenovoNow components have been uninstalled." } $filename = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\User Guide.lnk" if (Test-Path $filename) { Remove-Item -Path $filename -Force } ##Also delete this directory %programdata%\Lenovo\UserGuide\ $userguidepath = "C:\ProgramData\Lenovo\UserGuide" if (Test-Path $userguidepath) { Remove-Item -Path $userguidepath -Recurse -Force } $userguidepath2 = "C:\User Guide.ico" if (Test-Path $userguidepath2) { Remove-Item -Path $userguidepath2 -Recurse -Force } $AIPolicy = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Lenovo Responsible AI Policy.url" if (Test-Path $AIPolicy) { Remove-Item -Path $AIPolicy -Recurse -Force } $filenameDE1 = "C:\Users\All Users\Microsoft\Windows\Start Menu\Programs\Benutzerhandbuch.url" if (Test-Path $filenameDE1) { Remove-Item -Path $filenameDE1 -Force } $filenameDE2 = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Benutzerhandbuch.url" if (Test-Path $filenameDE2) { Remove-Item -Path $filenameDE2 -Force } ##Camera fix for Lenovo E14 $model = Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object -ExpandProperty Model if ($model -eq "21E30001MY") { $keypath = "HKLM:\SOFTWARE\\Microsoft\Windows Media Foundation\Platform" $keyname = "EnableFrameServerMode" $value = 0 if (!(Test-Path $keypath)) { New-Item -Path $keypath -Force } Set-ItemProperty -Path $keypath -Name $keyname -Value $value -Type DWord -Force $keypath2 = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows Media Foundation\Platform" if (!(Test-Path $keypath2)) { New-Item -Path $keypath2 -Force } Set-ItemProperty -Path $keypath2 -Name $keyname -Value $value -Type DWord -Force } ##Remove Lenovo theme and background image $registryPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes" # Check and remove ThemeName if it exists if (Get-ItemProperty -Path $registryPath -Name "ThemeName" -ErrorAction SilentlyContinue) { Remove-ItemProperty -Path $registryPath -Name "ThemeName" } # Check and remove DesktopBackground if it exists if (Get-ItemProperty -Path $registryPath -Name "DesktopBackground" -ErrorAction SilentlyContinue) { Remove-ItemProperty -Path $registryPath -Name "DesktopBackground" } ##Remove X-Rite if it exists $xritePath = "C:\Program Files (x86)\X-Rite Color Assistant\unins000.exe" if (Test-Path $xritePath) { Start-Process -FilePath $xritePath -ArgumentList "/SILENT" -Wait write-output "X-Rite Color Assistant uninstalled." } else { write-output "X-Rite Color Assistant uninstaller not found." } ##Stop Lenovo UDC Service and Disable it write-output "Stopping and disabling Lenovo UDC Service" Stop-Service "UDCService" Set-Service "UDCService" -StartupType Disabled write-output "Lenovo UDC Service Disabled" } if ($manufacturer -like "*Samsung*") { write-output "Samsung detected" #Remove Samsung bloat ##Samsung Specific $UninstallPrograms = @( "ColorEngine" "Display Profile" "Galaxy Book Smart Switch service" "Live Wallpaper Service" "Quick Search Service" "Samsung Recovery Service" "Samsung Update Service" "Studio mode" "Bixby" "Galaxy Book Experience" "Galaxy Book Smart Switch" "Goodnotes for GalaxyBook" "Live Wallpaper" "Multi Control" "Quick Search" "Quick Share" "Samsung Account" "Samsung Analytics Agent" "Samsung Care+" "Samsung Cloud" "Samsung Continuity Service" "Samsung Device Care" "Samsung Flow" "Samsung Gallery" "Samsung Notes" "Samsung Recovery" "Samsung Settings" "Samsung Settings Runtime" "Samsung Studio" "Samsung Studio for Gallery" "Samsung Update" "SamsungPhone" "Screen Recorder" "Second Screen" "SmartThings" ) $UninstallPrograms = $UninstallPrograms | Where-Object { $appstoignore -notcontains $_ } $InstalledPrograms = $allstring | Where-Object { $UninstallPrograms -contains $_.Name } foreach ($app in $UninstallPrograms) { if (Get-AppxProvisionedPackage -Online | Where-Object DisplayName -like $app -ErrorAction SilentlyContinue) { Get-AppxProvisionedPackage -Online | Where-Object DisplayName -like $app | Remove-AppxProvisionedPackage -Online write-output "Removed provisioned package for $app." } else { write-output "Provisioned package for $app not found." } if (Get-AppxPackage -allusers -Name $app -ErrorAction SilentlyContinue) { Get-AppxPackage -allusers -Name $app | Remove-AppxPackage -AllUsers write-output "Removed $app." } else { write-output "$app not found." } UninstallAppFull -appName $app } # Process each package pattern foreach ($pattern in $uninstallPrograms) { $patternName = $pattern $minVersion = $pattern.MinVersion Write-Output "Checking for packages matching pattern: $patternName" # Search for matching packages in the registry $matchingPackages = @() # Check in 32-bit and 64-bit registry locations $registryPaths = @( "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*", "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" ) foreach ($registryPath in $registryPaths) { $packages = Get-ItemProperty -Path $registryPath -ErrorAction SilentlyContinue | Where-Object { $_.DisplayName -match [regex]::Escape($patternName) } # Filter by minimum version if specified if ($minVersion -and $packages) { $packages = $packages | Where-Object { if ($_.DisplayVersion) { try { [version]$_.DisplayVersion -ge [version]$minVersion } catch { # If version comparison fails, include it anyway for safety $true } } else { # If no version information, include it for safety $true } } } $matchingPackages += $packages } if ($matchingPackages.Count -eq 0) { Write-Output "No packages found matching pattern: $patternName" continue } Write-Output "Found $($matchingPackages.Count) package(s) matching pattern: $patternName" # Process each matching package foreach ($package in $matchingPackages) { $displayName = $package.DisplayName $uninstallString = $package.UninstallString $quietUninstallString = $package.QuietUninstallString $version = $package.DisplayVersion Write-Output "Attempting to uninstall: $displayName (Version: $version)" # Try to use the UninstallAppFull function first Write-Output "Trying to uninstall via UninstallAppFull..." UninstallAppFull -appName $displayName ##Skip the fallback if UninstallAppFull already removed the app if (-not (Test-Path $package.PSPath)) { Write-Output "$displayName removed by UninstallAppFull, skipping fallback" continue } # If UninstallAppFull doesn't work, fall back to direct uninstallation # Check if uninstall string exists and attempt uninstall if ($quietUninstallString) { Write-Output "Using quiet uninstall string: $quietUninstallString" try { if ($quietUninstallString -match "msiexec") { # For MSI-based uninstalls, add /quiet $uninstallCommand = $quietUninstallString + " /quiet" Start-Process "cmd.exe" -ArgumentList "/c $uninstallCommand" -Wait -NoNewWindow } else { # For EXE-based uninstalls ##Use parseExeUninstall so quoted paths containing spaces parse correctly $parsedQuiet = @(parseExeUninstall -exeString $quietUninstallString) $uninstallExe = $parsedQuiet[0].Trim('"') $uninstallArgs = @($parsedQuiet | Select-Object -Skip 1) $quietStartParams = @{ FilePath = $uninstallExe; Wait = $true; NoNewWindow = $true } if ($uninstallArgs.Count -gt 0) { $quietStartParams['ArgumentList'] = $uninstallArgs } Start-Process @quietStartParams } Write-Output "Quiet uninstall completed for: $displayName" } catch { Write-Output "Error during quiet uninstall: $_" } } elseif ($uninstallString) { Write-Output "Using standard uninstall string: $uninstallString" try { if ($uninstallString -match "msiexec") { # For MSI-based uninstalls, add /quiet if ($uninstallString -match "/I{") { # Change /I to /X for uninstall if needed $uninstallString = $uninstallString -replace "/I", "/X" } $uninstallCommand = $uninstallString + " /quiet" Start-Process "cmd.exe" -ArgumentList "/c $uninstallCommand" -Wait -NoNewWindow } else { # For EXE-based uninstalls ##Use parseExeUninstall so quoted paths containing spaces parse correctly $parsedStandard = @(parseExeUninstall -exeString $uninstallString) $uninstallExe = $parsedStandard[0].Trim('"') $uninstallArgs = @($parsedStandard | Select-Object -Skip 1) # Add silent parameters for common installers if ($uninstallString -match "uninstall.exe|uninst.exe|setup.exe|installer.exe") { $uninstallArgs += @("/S", "/silent", "/quiet", "/uninstall") } $standardStartParams = @{ FilePath = $uninstallExe; Wait = $true; NoNewWindow = $true } if ($uninstallArgs.Count -gt 0) { $standardStartParams['ArgumentList'] = $uninstallArgs } Start-Process @standardStartParams } Write-Output "Standard uninstall completed for: $displayName" } catch { Write-Output "Error during standard uninstall: $_" } } else { Write-Output "No uninstall string found for: $displayName" } } } write-output "Removed Samsung bloat" } if ($manufacturer -like "*Acer*") { write-output "Acer detected" #Remove Acer bloat $processnames = @( "ACCSvc.exe" "QASvc.exe" "ProShieldService.exe" ) foreach ($process in $processnames) { write-output "Stopping Process $process" Get-Process -Name $process | Stop-Process -Force write-output "Process $process Stopped" } ##Acer Specific $UninstallPrograms = @( "Acer Configuration Manager" "Acer Jumpstart" "Acer Product Registration" "Acer ProShield Plus" "Acer ProShield Plus Service" "Acer Purified Voice Console" "Acer Control Centre" "Acer Quick Access" "Acer Quick Access Service" "Password Generator Tool" "Evernote" "Dropbox promotion" "Acer User Experience Improvement Program Service" "DriverSetupUtility" "ControlCenter Service" "McAfee LiveSafe" "Quick Access Service" "User Experience Improvement Program Service" "McAfee.wps" "McAfeeWPSSparsePackage" "Evernote.Evernote" "C27EB4BA.DropboxOEM" "{2B51C83A-465D-4EA9-9CDC-1ED95ED09AC6}" "InsydeSoftwareCorp.AcerProShieldPlus" "Evernote.Evernote" "DTSInc.DTSAudioProcessing" "C27EB4BA.DropboxOEM" "AppUp.IntelOptaneMemoryandStorageManagement" "AcerIncorporated.QuickAccess" "AcerIncorporated.AcerRegistration" "AcerIncorporated.4703949AD09F" "AcerIncorporated.AcerPurifiedVoiceConsoleR" "55121DominqueTerry.PasswordGeneratorTool" ) $UninstallPrograms = $UninstallPrograms | Where-Object { $appstoignore -notcontains $_ } $InstalledPrograms = $allstring | Where-Object { $UninstallPrograms -contains $_.Name } foreach ($app in $UninstallPrograms) { if (Get-AppxProvisionedPackage -Online | Where-Object DisplayName -like $app -ErrorAction SilentlyContinue) { Get-AppxProvisionedPackage -Online | Where-Object DisplayName -like $app | Remove-AppxProvisionedPackage -Online write-output "Removed provisioned package for $app." } else { write-output "Provisioned package for $app not found." } if (Get-AppxPackage -allusers -Name $app -ErrorAction SilentlyContinue) { Get-AppxPackage -allusers -Name $app | Remove-AppxPackage -AllUsers write-output "Removed $app." } else { write-output "$app not found." } UninstallAppFull -appName $app } # Process each package pattern foreach ($pattern in $uninstallPrograms) { $patternName = $pattern $minVersion = $pattern.MinVersion Write-Output "Checking for packages matching pattern: $patternName" # Search for matching packages in the registry $matchingPackages = @() # Check in 32-bit and 64-bit registry locations $registryPaths = @( "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*", "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" ) foreach ($registryPath in $registryPaths) { $packages = Get-ItemProperty -Path $registryPath -ErrorAction SilentlyContinue | Where-Object { $_.DisplayName -match [regex]::Escape($patternName) } # Filter by minimum version if specified if ($minVersion -and $packages) { $packages = $packages | Where-Object { if ($_.DisplayVersion) { try { [version]$_.DisplayVersion -ge [version]$minVersion } catch { # If version comparison fails, include it anyway for safety $true } } else { # If no version information, include it for safety $true } } } $matchingPackages += $packages } if ($matchingPackages.Count -eq 0) { Write-Output "No packages found matching pattern: $patternName" continue } Write-Output "Found $($matchingPackages.Count) package(s) matching pattern: $patternName" # Process each matching package foreach ($package in $matchingPackages) { $displayName = $package.DisplayName $uninstallString = $package.UninstallString $quietUninstallString = $package.QuietUninstallString $version = $package.DisplayVersion Write-Output "Attempting to uninstall: $displayName (Version: $version)" # Try to use the UninstallAppFull function first Write-Output "Trying to uninstall via UninstallAppFull..." UninstallAppFull -appName $displayName ##Skip the fallback if UninstallAppFull already removed the app if (-not (Test-Path $package.PSPath)) { Write-Output "$displayName removed by UninstallAppFull, skipping fallback" continue } # If UninstallAppFull doesn't work, fall back to direct uninstallation # Check if uninstall string exists and attempt uninstall if ($quietUninstallString) { Write-Output "Using quiet uninstall string: $quietUninstallString" try { if ($quietUninstallString -match "msiexec") { # For MSI-based uninstalls, add /quiet $uninstallCommand = $quietUninstallString + " /quiet" Start-Process "cmd.exe" -ArgumentList "/c $uninstallCommand" -Wait -NoNewWindow } else { # For EXE-based uninstalls ##Use parseExeUninstall so quoted paths containing spaces parse correctly $parsedQuiet = @(parseExeUninstall -exeString $quietUninstallString) $uninstallExe = $parsedQuiet[0].Trim('"') $uninstallArgs = @($parsedQuiet | Select-Object -Skip 1) $quietStartParams = @{ FilePath = $uninstallExe; Wait = $true; NoNewWindow = $true } if ($uninstallArgs.Count -gt 0) { $quietStartParams['ArgumentList'] = $uninstallArgs } Start-Process @quietStartParams } Write-Output "Quiet uninstall completed for: $displayName" } catch { Write-Output "Error during quiet uninstall: $_" } } elseif ($uninstallString) { Write-Output "Using standard uninstall string: $uninstallString" try { if ($uninstallString -match "msiexec") { # For MSI-based uninstalls, add /quiet if ($uninstallString -match "/I{") { # Change /I to /X for uninstall if needed $uninstallString = $uninstallString -replace "/I", "/X" } $uninstallCommand = $uninstallString + " /quiet" Start-Process "cmd.exe" -ArgumentList "/c $uninstallCommand" -Wait -NoNewWindow } else { # For EXE-based uninstalls ##Use parseExeUninstall so quoted paths containing spaces parse correctly $parsedStandard = @(parseExeUninstall -exeString $uninstallString) $uninstallExe = $parsedStandard[0].Trim('"') $uninstallArgs = @($parsedStandard | Select-Object -Skip 1) # Add silent parameters for common installers if ($uninstallString -match "uninstall.exe|uninst.exe|setup.exe|installer.exe") { $uninstallArgs += @("/S", "/silent", "/quiet", "/uninstall") } $standardStartParams = @{ FilePath = $uninstallExe; Wait = $true; NoNewWindow = $true } if ($uninstallArgs.Count -gt 0) { $standardStartParams['ArgumentList'] = $uninstallArgs } Start-Process @standardStartParams } Write-Output "Standard uninstall completed for: $displayName" } catch { Write-Output "Error during standard uninstall: $_" } } else { Write-Output "No uninstall string found for: $displayName" } } } write-output "Removed Samsung bloat" } ##Remove bookmarks ##Enumerate all users $users = Get-ChildItem -Path "C:\Users" -Directory foreach ($user in $users) { $userpath = $user.FullName $bookmarks = "C:\Users\$userpath\AppData\Local\Microsoft\Edge\User Data\Default\Bookmarks" ##Remove any files if they exist foreach ($bookmark in $bookmarks) { if (Test-Path -Path $bookmark) { Remove-Item -Path $bookmark -Force } } } if ($manufacturer -like "*Asus*") { write-output "Asus detected" #Remove Asus bloat ##ASUS OEMcode = B9ECED6F ##ASUS Specific ##You can decide which, if any, you wish to keep by including in customwhitelist $UninstallPrograms = @( "B9ECED6F.ASUSExpertWidget" #defines F1-F4 hotkeys on Expertbook "B9ECED6F.ASUSPCAssistant" #MyAsus App on Expertbook, Vivobook "AppUp.IntelGraphicsExperience" #Intel Graphic mgmt utility on Expertbook, Vivobook "AppUp.IntelManagementandSecurityStatus" #Intel Security mgmt utility on Expertbook "DolbyLaboratories.DolbyAccess" #Dolby sound utilities on Expertbook, Vivobook "DolbyLaboratories.DolbyDigitalPlusDecoderOEM" #Dolby sound utilities on Expertbook, Vivobook "DrivewintechTechnologyCo.DiracAudoManager" #sound mgmt utility in Vivobook "IntelligoTechnologyInc.541271065CCE8" #suite of voice/microphone AI and Meeting utilities that Asus packages in Expertbook ) $UninstallPrograms = $UninstallPrograms | Where-Object { $appstoignore -notcontains $_ } $InstalledPrograms = $allstring | Where-Object { $UninstallPrograms -contains $_.Name } foreach ($app in $UninstallPrograms) { if (Get-AppxProvisionedPackage -Online | Where-Object DisplayName -like $app -ErrorAction SilentlyContinue) { Get-AppxProvisionedPackage -Online | Where-Object DisplayName -like $app | Remove-AppxProvisionedPackage -Online write-output "Removed provisioned package for $app." } else { write-output "Provisioned package for $app not found." } if (Get-AppxPackage -allusers -Name $app -ErrorAction SilentlyContinue) { Get-AppxPackage -allusers -Name $app | Remove-AppxPackage -AllUsers write-output "Removed $app." } else { write-output "$app not found." } UninstallAppFull -appName $app } write-output "Removing Asus Theme and background " ##Remove Asus OEM theme and background image $registryPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes" # Check and remove ThemeName if it exists if (Get-ItemProperty -Path $registryPath -Name "ThemeName" -ErrorAction SilentlyContinue) { write-output "remove Asus Theme" Remove-ItemProperty -Path $registryPath -Name "ThemeName" } # Check and remove DesktopBackground if it exists if (Get-ItemProperty -Path $registryPath -Name "DesktopBackground" -ErrorAction SilentlyContinue) { write-output "Remove Asus deskbkgrnd" Remove-ItemProperty -Path $registryPath -Name "DesktopBackground" } #Clear the pre-defined ASUS OEM task bar definition file and registry key or it will override default user settings $tbfile = "C:\Windows\OEM\TaskbarLayoutModification.xml" if ((Test-Path -Path $tbfile -PathType Leaf) -and ((Get-Item $tbfile).LastWriteTimeUTC -lt $startUtc)) { write-output "remove asus taskbar" Remove-Item -Path $tbfile -Force } $registryPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer" $reg = Get-ItemProperty -Path $registryPath -ErrorAction SilentlyContinue if (($reg -and $reg.PSObject.Properties.Name -contains "LayoutXMLPath") -and ($reg.LayoutXMLPath -ieq $tbfile)) { write-output "remove Asus layoutxmlpath" Remove-ItemProperty -Path $registryPath -Name "LayoutXMLPath" } $registryPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer" $reg = Get-ItemProperty -Path $registryPath -ErrorAction SilentlyContinue if (($reg -and $reg.PSObject.Properties.Name -contains "LayoutXMLPath") -and ($reg.LayoutXMLPath -ieq $tbfile)) { write-output "remove Asus layoutxmlpath" Remove-ItemProperty -Path $registryPath -Name "LayoutXMLPath" -ErrorAction SilentlyContinue } } #end ASUS specific ############################################################################################################ ############################################################################ # END code from RemoveBloat.ps1 ############################################################################ } *>&1 | ForEach-Object { Write-Log "$_" 'DETAIL' } Write-Log "$($cs.Manufacturer) software removal finished (details are in the log)." 'OK' Write-Host '' Write-Log 'Done. Restart the PC to finish removing everything.' 'OK' Write-Host " Log: $LogFile" -ForegroundColor Gray Write-Host '' } catch { Write-Log "FAILED: $($_.Exception.Message)" 'ERROR' Write-Host " Log: $LogFile" -ForegroundColor Yellow Write-Host "" } }