Windows10SysPrepDebloater.ps1 13 KB

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