diff options
| -rw-r--r-- | .config/powershell/bloatware.ps1 | 129 |
1 files changed, 97 insertions, 32 deletions
diff --git a/.config/powershell/bloatware.ps1 b/.config/powershell/bloatware.ps1 index 833f7c7..0c9477f 100644 --- a/.config/powershell/bloatware.ps1 +++ b/.config/powershell/bloatware.ps1 @@ -1,5 +1,21 @@ # bloatware.ps1 +# Check if Registry key exists +function Check-RegistryKeyExists { + param( + [Parameter(Mandatory = $true)] + [string]$KeyPath + ) + + if (Test-Path $KeyPath) { + Write-Host "Registry key exists: $KeyPath" + return $true + } else { + Write-Host "Registry key does not exist: $KeyPath" + return $false + } +} + # Helper functions ------------------------ function force-mkdir($path) { if (!(Test-Path $path)) { @@ -17,7 +33,7 @@ $bloatware = @( #"Defender" "Feedback" "Flash" - #"Gaming" # Breaks Xbox Live Account Login + #"Gaming" # Breaks Xbox Live Account Login #"Holo" #"InternetExplorer" "Maps" @@ -30,34 +46,80 @@ $bloatware = @( # Remove Features ------------------------ foreach ($bloat in $bloatware) { - Write-Output "Removing packages containing $bloat" - $pkgs = (Get-ChildItem "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages" | - Where-Object Name -Like "*$bloat*") - - foreach ($pkg in $pkgs) { - $pkgname = $pkg.Name.split('\')[-1] - Takeown-Registry($pkg.Name) - Takeown-Registry($pkg.Name + "\Owners") - Set-ItemProperty -Path ("HKLM:" + $pkg.Name.Substring(18)) -Name Visibility -Value 1 - New-ItemProperty -Path ("HKLM:" + $pkg.Name.Substring(18)) -Name DefVis -PropertyType DWord -Value 2 - Remove-Item -Path ("HKLM:" + $pkg.Name.Substring(18) + "\Owners") - dism.exe /Online /Remove-Package /PackageName:$pkgname /NoRestart - } + Write-Output "Removing packages containing $bloat" + $pkgs = (Get-ChildItem "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages" | + Where-Object Name -Like "*$bloat*") + + foreach ($pkg in $pkgs) { + $pkgname = $pkg.Name.split('\')[-1] + Takeown-Registry($pkg.Name) + Takeown-Registry($pkg.Name + "\Owners") + Set-ItemProperty -Path ("HKLM:" + $pkg.Name.Substring(18)) -Name Visibility -Value 1 + New-ItemProperty -Path ("HKLM:" + $pkg.Name.Substring(18)) -Name DefVis -PropertyType DWord -Value 2 + Remove-Item -Path ("HKLM:" + $pkg.Name.Substring(18) + "\Owners") + dism.exe /Online /Remove-Package /PackageName:$pkgname /NoRestart + } } # Remove default apps and bloat ------------------------ Write-Output "Uninstalling default apps" foreach ($app in $apps) { - Write-Output "Trying to remove $app" - Get-AppxPackage -Name $app -AllUsers | Remove-AppxPackage -AllUsers - Get-AppXProvisionedPackage -Online | - Where-Object DisplayName -EQ $app | - Remove-AppxProvisionedPackage -Online + Write-Output "Trying to remove $app" + Get-AppxPackage -Name $app -AllUsers | Remove-AppxPackage -AllUsers + Get-AppXProvisionedPackage -Online | + Where-Object DisplayName -EQ $app | + Remove-AppxProvisionedPackage -Online } # Prevents "Suggested Applications" returning -force-mkdir "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Cloud Content" -Set-ItemProperty "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Cloud Content" "DisableWindowsConsumerFeatures" 1 +if (Check-RegistryKeyExists -KeyPath "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Cloud Content") { + Set-ItemProperty "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Cloud Content" "DisableWindowsConsumerFeatures" 1 +} + +# Disable Microsoft Edge sidebar +$RegistryPath = 'HKLM:\SOFTWARE\Policies\Microsoft\Edge' +$Name = 'HubsSidebarEnabled' +$Value = '00000000' +# Create the key if it does not exist +If (-NOT (Test-Path $RegistryPath)) { + New-Item -Path $RegistryPath -Force | Out-Null +} +New-ItemProperty -Path $RegistryPath -Name $Name -Value $Value -PropertyType DWORD -Force + +# Disable Microsoft Edge first-run Welcome screen +$RegistryPath = 'HKLM:\SOFTWARE\Policies\Microsoft\Edge' +$Name = 'HideFirstRunExperience' +$Value = '00000001' +# Create the key if it does not exist +If (-NOT (Test-Path $RegistryPath)) { + New-Item -Path $RegistryPath -Force | Out-Null +} +New-ItemProperty -Path $RegistryPath -Name $Name -Value $Value -PropertyType DWORD -Force + +# Remove Microsoft Edge ------------------------ +$ErrorActionPreference = "Stop" +$regView = [Microsoft.Win32.RegistryView]::Registry32 +$microsoft = [Microsoft.Win32.RegistryKey]::OpenBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $regView). +OpenSubKey('SOFTWARE\Microsoft', $true) +$edgeUWP = "$env:SystemRoot\SystemApps\Microsoft.MicrosoftEdge_8wekyb3d8bbwe" +$uninstallRegKey = $microsoft.OpenSubKey('Windows\CurrentVersion\Uninstall\Microsoft Edge') +$uninstallString = $uninstallRegKey.GetValue('UninstallString') + ' --force-uninstall' + +$edgeClient = $microsoft.OpenSubKey('EdgeUpdate\ClientState\{56EB18F8-B008-4CBD-B6D2-8C97FE7E9062}', $true) +if ($null -ne $edgeClient.GetValue('experiment_control_labels')) { + $edgeClient.DeleteValue('experiment_control_labels') +} +$microsoft.CreateSubKey('EdgeUpdateDev').SetValue('AllowUninstall', '') +[void](New-Item $edgeUWP -ItemType Directory -ErrorVariable fail -ErrorAction SilentlyContinue) +[void](New-Item "$edgeUWP\MicrosoftEdge.exe" -ErrorAction Continue) +Start-Process cmd.exe "/c $uninstallString" -WindowStyle Hidden -Wait +[void](Remove-Item "$edgeUWP\MicrosoftEdge.exe" -ErrorAction Continue) + +if (-not $fail) { + [void](Remove-Item "$edgeUWP") +} + +Write-Output "Edge should now be uninstalled!" # Kill OneDrive with fire ------------------------ Write-Output "Kill OneDrive process" @@ -82,15 +144,18 @@ If ((Get-ChildItem "$env:userprofile\OneDrive" -Recurse | Measure-Object).Count } Write-Output "Disable OneDrive via Group Policies" -force-mkdir "HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\OneDrive" -Set-ItemProperty "HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\OneDrive" "DisableFileSyncNGSC" 1 +if (Check-RegistryKeyExists -KeyPath "HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\OneDrive") { + Set-ItemProperty "HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\OneDrive" "DisableFileSyncNGSC" 1 +} -Write-Output "Remove Onedrive from explorer sidebar" +Write-Output "Remove OneDrive from explorer sidebar" New-PSDrive -PSProvider "Registry" -Root "HKEY_CLASSES_ROOT" -Name "HKCR" -force-mkdir "HKCR:\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" -Set-ItemProperty "HKCR:\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" "System.IsPinnedToNameSpaceTree" 0 -force-mkdir "HKCR:\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" -Set-ItemProperty "HKCR:\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" "System.IsPinnedToNameSpaceTree" 0 +if (Check-RegistryKeyExists -KeyPath "HKCR:\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}") { + Set-ItemProperty "HKCR:\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" "System.IsPinnedToNameSpaceTree" 0 +} +if (Check-RegistryKeyExists -KeyPath "HKCR:\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}") { + Set-ItemProperty "HKCR:\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" "System.IsPinnedToNameSpaceTree" 0 +} Remove-PSDrive "HKCR" # Thank you Matthew Israelsson @@ -99,7 +164,7 @@ reg load "hku\Default" "C:\Users\Default\NTUSER.DAT" reg delete "HKEY_USERS\Default\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "OneDriveSetup" /f reg unload "hku\Default" -Write-Output "Removing startmenu entry" +Write-Output "Removing start menu entry" Remove-Item -Force -ErrorAction SilentlyContinue "$env:userprofile\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk" Write-Output "Removing scheduled task" @@ -126,6 +191,6 @@ cd $HOME rm OneDrive -r -force # Prevents "Suggested Applications" returning -force-mkdir "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Cloud Content" -Set-ItemProperty "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Cloud Content" "DisableWindowsConsumerFeatures" 1 - +if (Check-RegistryKeyExists -KeyPath "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Cloud Content") { + Set-ItemProperty "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Cloud Content" "DisableWindowsConsumerFeatures" 1 +} |
