From 79d4a3d234036c858ed91a06e21bef7514bd8a25 Mon Sep 17 00:00:00 2001 From: seth Date: Fri, 1 Mar 2024 15:01:36 -0500 Subject: refactor debloat.ps1 --- debloat.ps1 | 92 +++++++++++++++++++++++++------------------------------------ 1 file changed, 38 insertions(+), 54 deletions(-) diff --git a/debloat.ps1 b/debloat.ps1 index 4543ef5..eaf4625 100644 --- a/debloat.ps1 +++ b/debloat.ps1 @@ -9,7 +9,7 @@ $VerbosePreference = "Continue" -function Add-Registry-Key { +function Add-Key { param ( [String]$Name, [String]$Path, @@ -17,7 +17,7 @@ function Add-Registry-Key { [System.Object]$Value ) - Write-Verbose -Message "Adding registry key $Path\$NAME" + Write-Verbose -Message "Adding registry key $Path\$Name" if (-not(Test-Path -Path $Path)) { Write-Verbose -Message "Creating registry path $Path" New-Item -Path $Path -Force @@ -25,29 +25,7 @@ function Add-Registry-Key { New-ItemProperty -Path $Path -Name $Name -Value $Value -PropertyType $Type -Force } -function Add-HKLM-Key { - param ( - [String]$Name, - [String]$Path, - [Microsoft.Win32.RegistryValueKind]$Type, - [System.Object]$Value - ) - - Add-Registry-Key -Path "HKLM:\$Path" -Name $Name -Value $Value -Type $Type -} - -function Add-HKCU-Key { - param ( - [String]$Name, - [String]$Path, - [Microsoft.Win32.RegistryValueKind]$Type, - [System.Object]$Value - ) - - Add-Registry-Key -Path "HKCU:\$Path" -Name $Name -Value $Value -Type $Type -} - -function Remove-Default-Package { +function Remove-DefaultPackage { param ( [String]$Name ) @@ -67,19 +45,19 @@ Write-Host "Starting post-install script!" # see https://learn.microsoft.com/en-us/windows/privacy/manage-connections-from-windows-operating-system-components-to-microsoft-services ## Disable Cortana and Web Search -Add-HKLM-Key -Path "SOFTWARE\Policies\Microsoft\Windows\Windows Search" -Name "AllowCortana" -Type DWord -Value 0 -Add-HKLM-Key -Path "SOFTWARE\Policies\Microsoft\Windows\Windows Search" -Name "AllowSearchToUseLocation" -Type DWord -Value 0 -Add-HKLM-Key -Path "SOFTWARE\Policies\Microsoft\Windows\Windows Search" -Name "DisableWebSearch" -Type DWord -Value 1 -Add-HKLM-Key -Path "SOFTWARE\Policies\Microsoft\Windows\Windows Search" -Name "ConnectedSearchUseWeb" -Type DWord -Value 0 +Add-Key -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Windows Search" -Name "AllowCortana" -Type DWord -Value 0 +Add-Key -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Windows Search" -Name "AllowSearchToUseLocation" -Type DWord -Value 0 +Add-Key -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Windows Search" -Name "DisableWebSearch" -Type DWord -Value 1 +Add-Key -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Windows Search" -Name "ConnectedSearchUseWeb" -Type DWord -Value 0 ## Disable OneDrive -Add-HKLM-Key -Path "SOFTWARE\Policies\Microsoft\Windows\OneDrive" -Name "DisableFileSyncNGSC" -Type DWord -Value 1 -Add-HKLM-Key -Path "SOFTWARE\Microsoft\OneDrive" -Name "PreventNetworkTrafficPreUserSignIn" -Type DWord -Value 1 +Add-Key -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\OneDrive" -Name "DisableFileSyncNGSC" -Type DWord -Value 1 +Add-Key -Path "HKLM:\SOFTWARE\Microsoft\OneDrive" -Name "PreventNetworkTrafficPreUserSignIn" -Type DWord -Value 1 ## Disable Advertising ID -Add-HKLM-Key -Path "SOFTWARE\Microsoft\Windows\CurrentVersion\AdvertisingInfo" -Name "Enabled" -Type DWord -Value 0 -Add-HKLM-Key -Path "SOFTWARE\Policies\Microsoft\Windows\AdvertisingInfo" -Name "DisabledByGroupPolicy" -Type DWord -Value 1 -Add-HKLM-Key -Path "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "Start_TrackProgs" -Type DWord -Value 0 +Add-Key -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AdvertisingInfo" -Name "Enabled" -Type DWord -Value 0 +Add-Key -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\AdvertisingInfo" -Name "DisabledByGroupPolicy" -Type DWord -Value 1 +Add-Key -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "Start_TrackProgs" -Type DWord -Value 0 ## Disable apps' access to some things $app_access = @( @@ -90,6 +68,7 @@ $app_access = @( "LetAppsAccessEmail" "LetAppsAccessMessaging" "LetAppsAccessPhone" + "LetAppsAccessRadios" "LetAppsAccessMotion" "LetAppsAccessTasks" "LetAppsGetDiagnosticInfo" @@ -98,35 +77,38 @@ $app_access = @( ) foreach ($access in $app_access) { - Add-HKLM-Key -Path "SOFTWARE\Policies\Microsoft\Windows\AppPrivacy" -Name $access -Type DWord -Value 2 + Add-Key "HKLM:\SOFTWARE\Policies\Microsoft\Windows\AppPrivacy" -Name $access -Type DWord -Value 2 } -Add-HKLM-Key -Path "SOFTWARE\Policies\Microsoft\Windows\Messaging" -Name "AllowMessageSync" -Type DWord -Value 0 +Add-Key "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Messaging" -Name "AllowMessageSync" -Type DWord -Value 0 ## Disable Feedback & diagnostics -Add-HKLM-Key -Path "SOFTWARE\Policies\Microsoft\Windows\DataCollection" -Name "DoNotShowFeedbackNotifications" -Type DWord -Value 1 -Add-HKLM-Key -Path "SOFTWARE\Policies\Microsoft\Windows\DataCollection" -Name "AllowTelemetry" -Type DWord -Value 0 -Add-HKLM-Key -Path "SOFTWARE\Policies\Microsoft\Windows\CloudContent" -Name "DisableWindowsConsumerFeatures" -Type DWord -Value 1 -Add-HKCU-Key -Path "SOFTWARE\Policies\Microsoft\Windows\CloudContent" -Name "DisableTailoredExperiencesWithDiagnosticData" -Type DWord -Value 1 +Add-Key -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection" -Name "DoNotShowFeedbackNotifications" -Type DWord -Value 1 +Add-Key -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection" -Name "AllowTelemetry" -Type DWord -Value 0 +Add-Key -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\CloudContent" -Name "DisableWindowsConsumerFeatures" -Type DWord -Value 1 +Add-Key -Path "HKCU:\SOFTWARE\Policies\Microsoft\Windows\CloudContent" -Name "DisableTailoredExperiencesWithDiagnosticData" -Type DWord -Value 1 ## Disable Inking & Typing data collection -Add-HKCU-Key -Path "SOFTWARE\Microsoft\InputPersonalization" -Name "RestrictImplicitTextCollection" -Type DWord -Value 1 -Add-HKCU-Key -Path "SOFTWARE\Microsoft\InputPersonalization" -Name "RestrictImplicitInkCollection" -Type DWord -Value 1 +Add-Key -Path "HKCU:\SOFTWARE\Microsoft\InputPersonalization" -Name "RestrictImplicitTextCollection" -Type DWord -Value 1 +Add-Key -Path "HKCU:\SOFTWARE\Microsoft\InputPersonalization" -Name "RestrictImplicitInkCollection" -Type DWord -Value 1 ## Disable Activity History -Add-HKLM-Key -Path "SOFTWARE\Policies\Microsoft\Windows\System" -Name "EnableActivityFeed" -Type DWord -Value 0 -Add-HKLM-Key -Path "SOFTWARE\Policies\Microsoft\Windows\System" -Name "PublishUserActivities" -Type DWord -Value 0 -Add-HKLM-Key -Path "SOFTWARE\Policies\Microsoft\Windows\System" -Name "UploadUserActivities" -Type DWord -Value 0 +Add-Key -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\System" -Name "EnableActivityFeed" -Type DWord -Value 0 +Add-Key -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\System" -Name "PublishUserActivities" -Type DWord -Value 0 +Add-Key -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\System" -Name "UploadUserActivities" -Type DWord -Value 0 ## Disable Windows Defender sample submission -Add-HKLM-Key -Path "SOFTWARE\Policies\Microsoft\Windows Defender\Spynet" -Name "SubmitSamplesConsent" -Type DWord -Value 2 +Add-Key "HKLM:\SOFTWARE\Policies\Microsoft\Windows Defender\Spynet" -Name "SubmitSamplesConsent" -Type DWord -Value 2 ## Disable News and interests -Add-HKLM-Key -Path "SOFTWARE\Policies\Microsoft\Windows\Windows Feeds" -Name "EnableFeeds" -Type DWord -Value 0 +Add-Key "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Windows Feeds" -Name "EnableFeeds" -Type DWord -Value 0 ## Disable Personalized Experiences -Add-HKCU-Key -Path "SOFTWARE\Policies\Microsoft\Windows\CloudContent" -Name "DisableWindowsSpotlightFeatures" -Type DWord -Value 1 -Add-HKCU-Key -Path "SOFTWARE\Policies\Microsoft\Windows\CloudContent" -Name "DisableCloudOptimizedContent" -Type DWord -Value 1 +Add-Key -Path "HKCU:\SOFTWARE\Policies\Microsoft\Windows\CloudContent" -Name "DisableWindowsSpotlightFeatures" -Type DWord -Value 1 +Add-Key -Path "HKCU:\SOFTWARE\Policies\Microsoft\Windows\CloudContent" -Name "DisableCloudOptimizedContent" -Type DWord -Value 1 + +## Disable Copilot +Add-Key "HKCU:\SOFTWARE\Policies\Microsoft\Windows\WindowsCopilot" -Name "TurnOffWindowsCopilot" -Type DWord -Value 1 # --- Remove Default Packages --- @@ -136,6 +118,12 @@ $packages = @( "Microsoft.BingFinance" "Microsoft.BingSports" "*.Twitter" + # "Microsoft.XboxApp" # this won't break much + # these will: + # "Microsoft.Xbox.TCUI" + # "Microsoft.XboxGameCallableUI" + # "Microsoft.XboxGamingOverlay" + # "Microsoft.XboxIdentityProvider" "Microsoft.Office.Sway" "Microsoft.Office.OneNote" "Microsoft.MicrosoftOfficeHub" @@ -144,7 +132,7 @@ $packages = @( ) foreach ($pkg in $packages) { - Remove-Default-Package -Name $pkg + Remove-DefaultPackage -Name $pkg } @@ -174,8 +162,4 @@ foreach ($service in $services) { } -# --- Disable Copilot --- -Add-HKCU-Key -Path "SOFTWARE\Policies\Microsoft\Windows\WindowsCopilot" -Name "TurnOffWindowsCopilot" -Type DWord -Value 1 - - Write-Host "Done!" -- cgit v1.2.3