Windows10SysPrepDebloater.ps1 14 KB

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