Windows10SysPrepDebloater.ps1 14 KB

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