Windows10SysPrepDebloater.ps1 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. #This function finds any AppX/AppXProvisioned package and uninstalls it, except for Freshpaint, Windows Calculator, Windows Store, and Windows Photos.
  2. #Also, to note - This does NOT remove essential system services/software/etc such as .NET framework installations, Cortana, Edge, etc.
  3. #This is the switch parameter for running this script as a 'silent' script, for use in MDT images or any type of mass deployment without user interaction.
  4. param (
  5. [switch]$Debloat, [switch]$SysPrep
  6. )
  7. Function Begin-SysPrep {
  8. param([switch]$SysPrep)
  9. Write-Verbose -Message ('Starting Sysprep Fixes')
  10. # Disable Windows Store Automatic Updates
  11. Write-Verbose -Message "Adding Registry key to Disable Windows Store Automatic Updates"
  12. $registryPath = "HKLM:\SOFTWARE\Policies\Microsoft\WindowsStore"
  13. If (!(Test-Path $registryPath)) {
  14. Mkdir $registryPath -ErrorAction SilentlyContinue
  15. New-ItemProperty $registryPath -Name AutoDownload -Value 2
  16. }
  17. Else {
  18. Set-ItemProperty $registryPath -Name AutoDownload -Value 2
  19. }
  20. #Stop WindowsStore Installer Service and set to Disabled
  21. Write-Verbose -Message ('Stopping InstallService')
  22. Stop-Service InstallService
  23. Write-Verbose -Message ('Setting InstallService Startup to Disabled')
  24. & Set-Service -Name InstallService -StartupType Disabled
  25. }
  26. #Creates a PSDrive to be able to access the 'HKCR' tree
  27. New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT
  28. Function Start-Debloat {
  29. param([switch]$Debloat)
  30. #Removes AppxPackages
  31. #Credit to Reddit user /u/GavinEke for a modified version of my whitelist code
  32. [regex]$WhitelistedApps = 'Microsoft.Paint3D|Microsoft.MSPaint|Microsoft.WindowsCalculator|Microsoft.WindowsStore|Microsoft.MicrosoftStickyNotes|Microsoft.WindowsSoundRecorder|Microsoft.Windows.Photos|CanonicalGroupLimited.UbuntuonWindows'
  33. Get-AppxPackage -AllUsers | Where-Object {$_.Name -NotMatch $WhitelistedApps} | Remove-AppxPackage -ErrorAction SilentlyContinue
  34. # Run this again to avoid error on 1803 or having to reboot.
  35. Get-AppxPackage -AllUsers | Where-Object {$_.Name -NotMatch $WhitelistedApps} | Remove-AppxPackage -ErrorAction SilentlyContinue
  36. Get-AppxProvisionedPackage -Online | Where-Object {$_.PackageName -NotMatch $WhitelistedApps} | Remove-AppxProvisionedPackage -Online -ErrorAction SilentlyContinue
  37. }
  38. Function Remove-Keys {
  39. Param([switch]$Debloat)
  40. #These are the registry keys that it will delete.
  41. $Keys = @(
  42. #Remove Background Tasks
  43. "HKCR:\Extensions\ContractId\Windows.BackgroundTasks\PackageId\46928bounde.EclipseManager_2.2.4.51_neutral__a5h4egax66k6y"
  44. "HKCR:\Extensions\ContractId\Windows.BackgroundTasks\PackageId\ActiproSoftwareLLC.562882FEEB491_2.6.18.18_neutral__24pqs290vpjk0"
  45. "HKCR:\Extensions\ContractId\Windows.BackgroundTasks\PackageId\Microsoft.MicrosoftOfficeHub_17.7909.7600.0_x64__8wekyb3d8bbwe"
  46. "HKCR:\Extensions\ContractId\Windows.BackgroundTasks\PackageId\Microsoft.PPIProjection_10.0.15063.0_neutral_neutral_cw5n1h2txyewy"
  47. "HKCR:\Extensions\ContractId\Windows.BackgroundTasks\PackageId\Microsoft.XboxGameCallableUI_1000.15063.0.0_neutral_neutral_cw5n1h2txyewy"
  48. "HKCR:\Extensions\ContractId\Windows.BackgroundTasks\PackageId\Microsoft.XboxGameCallableUI_1000.16299.15.0_neutral_neutral_cw5n1h2txyewy"
  49. #Windows File
  50. "HKCR:\Extensions\ContractId\Windows.File\PackageId\ActiproSoftwareLLC.562882FEEB491_2.6.18.18_neutral__24pqs290vpjk0"
  51. #Registry keys to delete if they aren't uninstalled by RemoveAppXPackage/RemoveAppXProvisionedPackage
  52. "HKCR:\Extensions\ContractId\Windows.Launch\PackageId\46928bounde.EclipseManager_2.2.4.51_neutral__a5h4egax66k6y"
  53. "HKCR:\Extensions\ContractId\Windows.Launch\PackageId\ActiproSoftwareLLC.562882FEEB491_2.6.18.18_neutral__24pqs290vpjk0"
  54. "HKCR:\Extensions\ContractId\Windows.Launch\PackageId\Microsoft.PPIProjection_10.0.15063.0_neutral_neutral_cw5n1h2txyewy"
  55. "HKCR:\Extensions\ContractId\Windows.Launch\PackageId\Microsoft.XboxGameCallableUI_1000.15063.0.0_neutral_neutral_cw5n1h2txyewy"
  56. "HKCR:\Extensions\ContractId\Windows.Launch\PackageId\Microsoft.XboxGameCallableUI_1000.16299.15.0_neutral_neutral_cw5n1h2txyewy"
  57. #Scheduled Tasks to delete
  58. "HKCR:\Extensions\ContractId\Windows.PreInstalledConfigTask\PackageId\Microsoft.MicrosoftOfficeHub_17.7909.7600.0_x64__8wekyb3d8bbwe"
  59. #Windows Protocol Keys
  60. "HKCR:\Extensions\ContractId\Windows.Protocol\PackageId\ActiproSoftwareLLC.562882FEEB491_2.6.18.18_neutral__24pqs290vpjk0"
  61. "HKCR:\Extensions\ContractId\Windows.Protocol\PackageId\Microsoft.PPIProjection_10.0.15063.0_neutral_neutral_cw5n1h2txyewy"
  62. "HKCR:\Extensions\ContractId\Windows.Protocol\PackageId\Microsoft.XboxGameCallableUI_1000.15063.0.0_neutral_neutral_cw5n1h2txyewy"
  63. "HKCR:\Extensions\ContractId\Windows.Protocol\PackageId\Microsoft.XboxGameCallableUI_1000.16299.15.0_neutral_neutral_cw5n1h2txyewy"
  64. #Windows Share Target
  65. "HKCR:\Extensions\ContractId\Windows.ShareTarget\PackageId\ActiproSoftwareLLC.562882FEEB491_2.6.18.18_neutral__24pqs290vpjk0"
  66. )
  67. #This writes the output of each key it is removing and also removes the keys listed above.
  68. ForEach ($Key in $Keys) {
  69. Write-Output "Removing $Key from registry"
  70. Remove-Item $Key -Recurse -ErrorAction SilentlyContinue
  71. }
  72. }
  73. Function Protect-Privacy {
  74. Param([switch]$Debloat)
  75. #Creates a PSDrive to be able to access the 'HKCR' tree
  76. New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT
  77. #Disables Windows Feedback Experience
  78. Write-Output "Disabling Windows Feedback Experience program"
  79. $Advertising = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AdvertisingInfo'
  80. If (Test-Path $Advertising) {
  81. Set-ItemProperty $Advertising -Name Enabled -Value 0 -Verbose
  82. }
  83. #Stops Cortana from being used as part of your Windows Search Function
  84. Write-Output "Stopping Cortana from being used as part of your Windows Search Function"
  85. $Search = 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\Windows Search'
  86. If (Test-Path $Search) {
  87. Set-ItemProperty $Search -Name AllowCortana -Value 0 -Verbose
  88. }
  89. #Stops the Windows Feedback Experience from sending anonymous data
  90. Write-Output "Stopping the Windows Feedback Experience program"
  91. $Period1 = 'HKCU:\Software\Microsoft\Siuf'
  92. $Period2 = 'HKCU:\Software\Microsoft\Siuf\Rules'
  93. $Period3 = 'HKCU:\Software\Microsoft\Siuf\Rules\PeriodInNanoSeconds'
  94. If (!(Test-Path $Period3)) {
  95. mkdir $Period1 -ErrorAction SilentlyContinue
  96. mkdir $Period2 -ErrorAction SilentlyContinue
  97. mkdir $Period3 -ErrorAction SilentlyContinue
  98. New-ItemProperty $Period3 -Name PeriodInNanoSeconds -Value 0 -Verbose -ErrorAction SilentlyContinue
  99. }
  100. Write-Output "Adding Registry key to prevent bloatware apps from returning"
  101. #Prevents bloatware applications from returning
  102. $registryPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\CloudContent"
  103. If (!(Test-Path $registryPath)) {
  104. Mkdir $registryPath -ErrorAction SilentlyContinue
  105. New-ItemProperty $registryPath -Name DisableWindowsConsumerFeatures -Value 1 -Verbose -ErrorAction SilentlyContinue
  106. }
  107. Write-Output "Setting Mixed Reality Portal value to 0 so that you can uninstall it in Settings"
  108. $Holo = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Holographic'
  109. If (Test-Path $Holo) {
  110. Set-ItemProperty $Holo -Name FirstRunSucceeded -Value 0 -Verbose
  111. }
  112. #Disables live tiles
  113. Write-Output "Disabling live tiles"
  114. $Live = 'HKCU:\SOFTWARE\Policies\Microsoft\Windows\CurrentVersion\PushNotifications'
  115. If (!(Test-Path $Live)) {
  116. mkdir $Live -ErrorAction SilentlyContinue
  117. New-ItemProperty $Live -Name NoTileApplicationNotification -Value 1 -Verbose
  118. }
  119. #Turns off Data Collection via the AllowTelemtry key by changing it to 0
  120. Write-Output "Turning off Data Collection"
  121. $DataCollection = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection'
  122. If (Test-Path $DataCollection) {
  123. Set-ItemProperty $DataCollection -Name AllowTelemetry -Value 0 -Verbose
  124. }
  125. #Disables People icon on Taskbar
  126. Write-Output "Disabling People icon on Taskbar"
  127. $People = 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\People'
  128. If (!(Test-Path $People)) {
  129. mkdir $People -ErrorAction SilentlyContinue
  130. New-ItemProperty $People -Name PeopleBand -Value 0 -Verbose
  131. }
  132. #Disables suggestions on start menu
  133. Write-Output "Disabling suggestions on the Start Menu"
  134. $Suggestions = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager'
  135. If (Test-Path $Suggestions) {
  136. Set-ItemProperty $Suggestions -Name SystemPaneSuggestionsEnabled -Value 0 -Verbose
  137. }
  138. #Loads the registry keys/values below into the NTUSER.DAT file which prevents the apps from redownloading. Credit to a60wattfish
  139. reg load HKU\Default_User C:\Users\Default\NTUSER.DAT
  140. Set-ItemProperty -Path Registry::HKU\Default_User\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager -Name SystemPaneSuggestionsEnabled -Value 0
  141. Set-ItemProperty -Path Registry::HKU\Default_User\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager -Name PreInstalledAppsEnabled -Value 0
  142. Set-ItemProperty -Path Registry::HKU\Default_User\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager -Name OemPreInstalledAppsEnabled -Value 0
  143. reg unload HKU\Default_User
  144. #Disables scheduled tasks that are considered unnecessary
  145. Write-Output "Disabling scheduled tasks"
  146. #Get-ScheduledTask -TaskName XblGameSaveTaskLogon | Disable-ScheduledTask -ErrorAction SilentlyContinue
  147. Get-ScheduledTask -TaskName XblGameSaveTask | Disable-ScheduledTask -ErrorAction SilentlyContinue
  148. Get-ScheduledTask -TaskName Consolidator | Disable-ScheduledTask -ErrorAction SilentlyContinue
  149. Get-ScheduledTask -TaskName UsbCeip | Disable-ScheduledTask -ErrorAction SilentlyContinue
  150. Get-ScheduledTask -TaskName DmClient | Disable-ScheduledTask -ErrorAction SilentlyContinue
  151. Get-ScheduledTask -TaskName DmClientOnScenarioDownload | Disable-ScheduledTask -ErrorAction SilentlyContinue
  152. }
  153. #This includes fixes by xsisbest
  154. Function FixWhitelistedApps {
  155. Param([switch]$Debloat)
  156. If(!(Get-AppxPackage -AllUsers | Select Microsoft.Paint3D, Microsoft.MSPaint, Microsoft.WindowsCalculator, Microsoft.WindowsStore, Microsoft.MicrosoftStickyNotes, Microsoft.WindowsSoundRecorder, Microsoft.Windows.Photos)) {
  157. #Credit to abulgatz for the 4 lines of code
  158. Get-AppxPackage -allusers Microsoft.Paint3D | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
  159. Get-AppxPackage -allusers Microsoft.MSPaint | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
  160. Get-AppxPackage -allusers Microsoft.WindowsCalculator | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
  161. Get-AppxPackage -allusers Microsoft.WindowsStore | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
  162. Get-AppxPackage -allusers Microsoft.MicrosoftStickyNotes | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
  163. Get-AppxPackage -allusers Microsoft.WindowsSoundRecorder | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
  164. Get-AppxPackage -allusers Microsoft.Windows.Photos | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"} }
  165. }
  166. Function CheckService {
  167. Param([switch]$Debloat)
  168. If (Get-Service -Name dmwappushservice | Where-Object {$_.Status -eq "Stopped"}) {
  169. Start-Service -Name dmwappushservice }
  170. }
  171. Write-Output "Initiating Sysprep"
  172. Begin-SysPrep
  173. Write-Output "Removing bloatware apps."
  174. Start-Debloat
  175. Write-Output "Removing leftover bloatware registry keys."
  176. Remove-Keys
  177. Write-Output "Checking to see if any Whitelisted Apps were removed, and if so re-adding them."
  178. FixWhitelistedApps
  179. Write-Output "Stopping telemetry, disabling unneccessary scheduled tasks, and preventing bloatware from returning."
  180. Protect-Privacy
  181. #Write-Output "Stopping Edge from taking over as the default PDF Viewer."
  182. #Stop-EdgePDF
  183. Write-Output "Finished all tasks."