Windows10SysPrepDebloater.ps1 13 KB

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