Windows10SysPrepDebloater.ps1 13 KB

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