Windows10SysPrepDebloater.ps1 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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, [Switch]$Privacy
  6. )
  7. $ErrorActionPreference = 'SilentlyContinue'
  8. Function Remove-AppxPackagesForSysprep {
  9. $AppXApps = @(
  10. #Unnecessary Windows 10 AppX Apps
  11. "*Microsoft.BingNews*"
  12. "*Microsoft.GetHelp*"
  13. "*Microsoft.Getstarted*"
  14. "*Microsoft.Messaging*"
  15. "*Microsoft.Microsoft3DViewer*"
  16. "*Microsoft.MicrosoftOfficeHub*"
  17. "*Microsoft.MicrosoftSolitaireCollection*"
  18. "*Microsoft.NetworkSpeedTest*"
  19. "*Microsoft.Office.OneNote*"
  20. "*Microsoft.Office.Sway*"
  21. "*Microsoft.OneConnect*"
  22. "*Microsoft.People*"
  23. "*Microsoft.Print3D*"
  24. "*Microsoft.SkypeApp*"
  25. "*Microsoft.StorePurchaseApp*"
  26. "*Microsoft.WindowsAlarms*"
  27. "*Microsoft.WindowsCamera*"
  28. "*microsoft.windowscommunicationsapps*"
  29. "*Microsoft.WindowsFeedbackHub*"
  30. "*Microsoft.WindowsMaps*"
  31. "*Microsoft.WindowsSoundRecorder*"
  32. "*Microsoft.Xbox.TCUI*"
  33. "*Microsoft.XboxApp*"
  34. "*Microsoft.XboxGameOverlay*"
  35. "*Microsoft.XboxIdentityProvider*"
  36. "*Microsoft.XboxSpeechToTextOverlay*"
  37. "*Microsoft.ZuneMusic*"
  38. "*Microsoft.ZuneVideo*"
  39. #Sponsored Windows 10 AppX Apps
  40. #Add sponsored/featured apps to remove in the "*AppName*" format
  41. "*EclipseManager*"
  42. "*ActiproSoftwareLLC*"
  43. "*AdobeSystemsIncorporated.AdobePhotoshopExpress*"
  44. "*Duolingo-LearnLanguagesforFree*"
  45. "*PandoraMediaInc*"
  46. "*CandyCrush*"
  47. "*Wunderlist*"
  48. "*Flipboard*"
  49. "*Twitter*"
  50. "*Facebook*"
  51. "*Spotify*"
  52. #Optional: Typically not removed but you can if you need to for some reason
  53. #"*Microsoft.Advertising.Xaml_10.1712.5.0_x64__8wekyb3d8bbwe*"
  54. #"*Microsoft.Advertising.Xaml_10.1712.5.0_x86__8wekyb3d8bbwe*"
  55. #"*Microsoft.BingWeather*"
  56. #"*Microsoft.MSPaint*"
  57. #"*Microsoft.MicrosoftStickyNotes*"
  58. #"*Microsoft.Windows.Photos*"
  59. #"*Microsoft.WindowsCalculator*"
  60. #"*Microsoft.WindowsStore*"
  61. )
  62. foreach ($App in $AppXApps) {
  63. Write-Verbose -Message ('Removing Package {0}' -f $App)
  64. Get-AppxPackage -Name $App | Remove-AppxPackage -ErrorAction SilentlyContinue
  65. Get-AppxPackage -Name $App -AllUsers | Remove-AppxPackage -AllUsers -ErrorAction SilentlyContinue
  66. Get-AppxProvisionedPackage -Online | Where-Object DisplayName -like $App | Remove-AppxProvisionedPackage -Online -ErrorAction SilentlyContinue
  67. }
  68. }
  69. #This will run get-appxpackage | remove-appxpackage which is required for sysprep to provision the apps.
  70. Function Begin-SysPrep {
  71. param([switch]$SysPrep)
  72. IF ($SysPrep) {
  73. Write-Verbose -Message ('Starting Sysprep Fixes')
  74. Write-Verbose -Message ('Removing AppXPackages for current user')
  75. get-appxpackage | remove-appxpackage -ErrorAction SilentlyContinue
  76. Remove-AppxPackagesForSysprep -ErrorAction SilentlyContinue
  77. # Disable Windows Store Automatic Updates
  78. Write-Verbose -Message "Adding Registry key to Disable Windows Store Automatic Updates"
  79. $registryPath = "HKLM:\SOFTWARE\Policies\Microsoft\WindowsStore"
  80. If (!(Test-Path $registryPath)) {
  81. Mkdir $registryPath -ErrorAction SilentlyContinue
  82. New-ItemProperty $registryPath -Name AutoDownload -Value 2 -ErrorAction SilentlyContinue
  83. }
  84. Else {
  85. Set-ItemProperty $registryPath -Name AutoDownload -Value 2 -ErrorAction SilentlyContinue
  86. }
  87. # Disable Microsoft Consumer Experience
  88. Write-Verbose -Message "Adding Registry key to prevent bloatware apps from returning"
  89. #Prevents bloatware applications from returning
  90. $registryPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\CloudContent"
  91. If (!(Test-Path $registryPath)) {
  92. Mkdir $registryPath -ErrorAction SilentlyContinue
  93. New-ItemProperty $registryPath -Name DisableWindowsConsumerFeatures -Value 1 -ErrorAction SilentlyContinue
  94. }
  95. Else {
  96. Set-ItemProperty $registryPath -Name DisableWindowsConsumerFeatures -Value 1 -ErrorAction SilentlyContinue
  97. }
  98. #Stop WindowsStore Installer Service and set to Disabled
  99. Write-Verbose -Message ('Stopping InstallService')
  100. Stop-Service InstallService
  101. Write-Verbose -Message ('Setting InstallService Startup to Disabled')
  102. & sc config InstallService start=disabled
  103. }
  104. }
  105. Function Start-Debloat {
  106. param([switch]$Debloat)
  107. IF ($Debloat) {
  108. #Removes AppxPackages
  109. #Credit to Reddit user /u/GavinEke for a modified version of my whitelist code
  110. Write-Verbose -Message ('Starting Debloat')
  111. [regex]$WhitelistedApps = 'Microsoft.Paint3D|Microsoft.WindowsCalculator|Microsoft.WindowsStore|Microsoft.Windows.Photos|CanonicalGroupLimited.UbuntuonWindows'
  112. Get-AppxPackage -AllUsers | Where-Object {$_.Name -NotMatch $WhitelistedApps} | Remove-AppxPackage -ErrorAction SilentlyContinue
  113. Get-AppxProvisionedPackage -Online | Where-Object {$_.PackageName -NotMatch $WhitelistedApps} | Remove-AppxProvisionedPackage -Online -ErrorAction SilentlyContinue
  114. }
  115. }
  116. Function Remove-Keys {
  117. Param([switch]$Debloat)
  118. if ($Debloat) {
  119. #Creates a PSDrive to be able to access the 'HKCR' tree
  120. New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT
  121. #These are the registry keys that it will delete.
  122. $Keys = @(
  123. #Remove Background Tasks
  124. "HKCR:\Extensions\ContractId\Windows.BackgroundTasks\PackageId\46928bounde.EclipseManager_2.2.4.51_neutral__a5h4egax66k6y"
  125. "HKCR:\Extensions\ContractId\Windows.BackgroundTasks\PackageId\ActiproSoftwareLLC.562882FEEB491_2.6.18.18_neutral__24pqs290vpjk0"
  126. "HKCR:\Extensions\ContractId\Windows.BackgroundTasks\PackageId\Microsoft.MicrosoftOfficeHub_17.7909.7600.0_x64__8wekyb3d8bbwe"
  127. "HKCR:\Extensions\ContractId\Windows.BackgroundTasks\PackageId\Microsoft.PPIProjection_10.0.15063.0_neutral_neutral_cw5n1h2txyewy"
  128. "HKCR:\Extensions\ContractId\Windows.BackgroundTasks\PackageId\Microsoft.XboxGameCallableUI_1000.15063.0.0_neutral_neutral_cw5n1h2txyewy"
  129. "HKCR:\Extensions\ContractId\Windows.BackgroundTasks\PackageId\Microsoft.XboxGameCallableUI_1000.16299.15.0_neutral_neutral_cw5n1h2txyewy"
  130. #Windows File
  131. "HKCR:\Extensions\ContractId\Windows.File\PackageId\ActiproSoftwareLLC.562882FEEB491_2.6.18.18_neutral__24pqs290vpjk0"
  132. #Registry keys to delete if they aren't uninstalled by RemoveAppXPackage/RemoveAppXProvisionedPackage
  133. "HKCR:\Extensions\ContractId\Windows.Launch\PackageId\46928bounde.EclipseManager_2.2.4.51_neutral__a5h4egax66k6y"
  134. "HKCR:\Extensions\ContractId\Windows.Launch\PackageId\ActiproSoftwareLLC.562882FEEB491_2.6.18.18_neutral__24pqs290vpjk0"
  135. "HKCR:\Extensions\ContractId\Windows.Launch\PackageId\Microsoft.PPIProjection_10.0.15063.0_neutral_neutral_cw5n1h2txyewy"
  136. "HKCR:\Extensions\ContractId\Windows.Launch\PackageId\Microsoft.XboxGameCallableUI_1000.15063.0.0_neutral_neutral_cw5n1h2txyewy"
  137. "HKCR:\Extensions\ContractId\Windows.Launch\PackageId\Microsoft.XboxGameCallableUI_1000.16299.15.0_neutral_neutral_cw5n1h2txyewy"
  138. #Scheduled Tasks to delete
  139. "HKCR:\Extensions\ContractId\Windows.PreInstalledConfigTask\PackageId\Microsoft.MicrosoftOfficeHub_17.7909.7600.0_x64__8wekyb3d8bbwe"
  140. #Windows Protocol Keys
  141. "HKCR:\Extensions\ContractId\Windows.Protocol\PackageId\ActiproSoftwareLLC.562882FEEB491_2.6.18.18_neutral__24pqs290vpjk0"
  142. "HKCR:\Extensions\ContractId\Windows.Protocol\PackageId\Microsoft.PPIProjection_10.0.15063.0_neutral_neutral_cw5n1h2txyewy"
  143. "HKCR:\Extensions\ContractId\Windows.Protocol\PackageId\Microsoft.XboxGameCallableUI_1000.15063.0.0_neutral_neutral_cw5n1h2txyewy"
  144. "HKCR:\Extensions\ContractId\Windows.Protocol\PackageId\Microsoft.XboxGameCallableUI_1000.16299.15.0_neutral_neutral_cw5n1h2txyewy"
  145. #Windows Share Target
  146. "HKCR:\Extensions\ContractId\Windows.ShareTarget\PackageId\ActiproSoftwareLLC.562882FEEB491_2.6.18.18_neutral__24pqs290vpjk0"
  147. )
  148. #This writes the output of each key it is removing and also removes the keys listed above.
  149. ForEach ($Key in $Keys) {
  150. Write-Output "Removing $Key from registry"
  151. Remove-Item $Key -Recurse -ErrorAction SilentlyContinue
  152. }
  153. }
  154. }
  155. Function Protect-Privacy {
  156. Param([switch]$Privacy)
  157. if ($Privacy) {
  158. Write-Verbose -Message ('Starting Protect Privacy')
  159. #Creates a PSDrive to be able to access the 'HKCR' tree
  160. New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT
  161. #Disables Windows Feedback Experience
  162. Write-Output "Disabling Windows Feedback Experience program"
  163. $Advertising = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AdvertisingInfo'
  164. If (Test-Path $Advertising) {
  165. Set-ItemProperty $Advertising -Name Enabled -Value 0 -Verbose
  166. }
  167. #Stops Cortana from being used as part of your Windows Search Function
  168. Write-Output "Stopping Cortana from being used as part of your Windows Search Function"
  169. $Search = 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\Windows Search'
  170. If (Test-Path $Search) {
  171. Set-ItemProperty $Search -Name AllowCortana -Value 0 -Verbose
  172. }
  173. #Stops the Windows Feedback Experience from sending anonymous data
  174. Write-Output "Stopping the Windows Feedback Experience program"
  175. $Period1 = 'HKCU:\Software\Microsoft\Siuf'
  176. $Period2 = 'HKCU:\Software\Microsoft\Siuf\Rules'
  177. $Period3 = 'HKCU:\Software\Microsoft\Siuf\Rules\PeriodInNanoSeconds'
  178. If (!(Test-Path $Period3)) {
  179. mkdir $Period1 -ErrorAction SilentlyContinue
  180. mkdir $Period2 -ErrorAction SilentlyContinue
  181. mkdir $Period3 -ErrorAction SilentlyContinue
  182. New-ItemProperty $Period3 -Name PeriodInNanoSeconds -Value 0 -Verbose -ErrorAction SilentlyContinue
  183. }
  184. Write-Output "Adding Registry key to prevent bloatware apps from returning"
  185. #Prevents bloatware applications from returning
  186. $registryPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\CloudContent"
  187. If (!(Test-Path $registryPath)) {
  188. Mkdir $registryPath -ErrorAction SilentlyContinue
  189. New-ItemProperty $registryPath -Name DisableWindowsConsumerFeatures -Value 1 -Verbose -ErrorAction SilentlyContinue
  190. }
  191. Write-Output "Setting Mixed Reality Portal value to 0 so that you can uninstall it in Settings"
  192. $Holo = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Holographic'
  193. If (Test-Path $Holo) {
  194. Set-ItemProperty $Holo -Name FirstRunSucceeded -Value 0 -Verbose
  195. }
  196. #Disables live tiles
  197. Write-Output "Disabling live tiles"
  198. $Live = 'HKCU:\SOFTWARE\Policies\Microsoft\Windows\CurrentVersion\PushNotifications'
  199. If (!(Test-Path $Live)) {
  200. mkdir $Live -ErrorAction SilentlyContinue
  201. New-ItemProperty $Live -Name NoTileApplicationNotification -Value 1 -Verbose
  202. }
  203. #Turns off Data Collection via the AllowTelemtry key by changing it to 0
  204. Write-Output "Turning off Data Collection"
  205. $DataCollection = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection'
  206. If (Test-Path $DataCollection) {
  207. Set-ItemProperty $DataCollection -Name AllowTelemetry -Value 0 -Verbose
  208. }
  209. #Disables People icon on Taskbar
  210. Write-Output "Disabling People icon on Taskbar"
  211. $People = 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\People'
  212. If (!(Test-Path $People)) {
  213. mkdir $People -ErrorAction SilentlyContinue
  214. New-ItemProperty $People -Name PeopleBand -Value 0 -Verbose
  215. }
  216. #Disables suggestions on start menu
  217. Write-Output "Disabling suggestions on the Start Menu"
  218. $Suggestions = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager'
  219. If (Test-Path $Suggestions) {
  220. Set-ItemProperty $Suggestions -Name SystemPaneSuggestionsEnabled -Value 0 -Verbose
  221. }
  222. #Loads the registry keys/values below into the NTUSER.DAT file which prevents the apps from redownloading. Credit to a60wattfish
  223. reg load HKU\Default_User C:\Users\Default\NTUSER.DAT
  224. Set-ItemProperty -Path Registry::HKU\Default_User\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager -Name SystemPaneSuggestionsEnabled -Value 0
  225. Set-ItemProperty -Path Registry::HKU\Default_User\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager -Name PreInstalledAppsEnabled -Value 0
  226. Set-ItemProperty -Path Registry::HKU\Default_User\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager -Name OemPreInstalledAppsEnabled -Value 0
  227. reg unload HKU\Default_User
  228. #Disables scheduled tasks that are considered unnecessary
  229. Write-Output "Disabling scheduled tasks"
  230. Get-ScheduledTask -TaskName XblGameSaveTaskLogon | Disable-ScheduledTask -ErrorAction SilentlyContinue
  231. Get-ScheduledTask -TaskName XblGameSaveTask | Disable-ScheduledTask -ErrorAction SilentlyContinue
  232. Get-ScheduledTask -TaskName Consolidator | Disable-ScheduledTask -ErrorAction SilentlyContinue
  233. Get-ScheduledTask -TaskName UsbCeip | Disable-ScheduledTask -ErrorAction SilentlyContinue
  234. Get-ScheduledTask -TaskName DmClient | Disable-ScheduledTask -ErrorAction SilentlyContinue
  235. Get-ScheduledTask -TaskName DmClientOnScenarioDownload | Disable-ScheduledTask -ErrorAction SilentlyContinue
  236. }
  237. }
  238. Function Stop-EdgePDF {
  239. param([switch]$StopEdgePDF)
  240. IF ($StopEdgePDF) {
  241. Write-Verbose -Message ('Starting StopEdge PDF')
  242. #Stops edge from taking over as the default .PDF viewer
  243. Write-Output "Stopping Edge from taking over as the default .PDF viewer"
  244. $NoOpen = 'HKCR:\.pdf'
  245. If (!(Get-ItemProperty $NoOpen -Name NoOpenWith)) {
  246. New-ItemProperty $NoOpen -Name NoOpenWith -Verbose -ErrorAction SilentlyContinue
  247. }
  248. $NoStatic = 'HKCR:\.pdf'
  249. If (!(Get-ItemProperty $NoStatic -Name NoStaticDefaultVerb)) {
  250. New-ItemProperty $NoStatic -Name NoStaticDefaultVerb -Verbose -ErrorAction SilentlyContinue
  251. }
  252. $NoOpen = 'HKCR:\.pdf\OpenWithProgids'
  253. If (!(Get-ItemProperty $NoOpen -Name NoOpenWith)) {
  254. New-ItemProperty $NoOpen -Name NoOpenWith -Verbose -ErrorAction SilentlyContinue
  255. }
  256. $NoStatic = 'HKCR:\.pdf\OpenWithProgids'
  257. If (!(Get-ItemProperty $NoStatic -Name NoStaticDefaultVerb)) {
  258. New-ItemProperty $NoStatic -Name NoStaticDefaultVerb -Verbose -ErrorAction SilentlyContinue
  259. }
  260. $NoOpen = 'HKCR:\.pdf\OpenWithList'
  261. If (!(Get-ItemProperty $NoOpen -Name NoOpenWith)) {
  262. New-ItemProperty $NoOpen -Name NoOpenWith -Verbose -ErrorAction SilentlyContinue
  263. }
  264. $NoStatic = 'HKCR:\.pdf\OpenWithList'
  265. If (!(Get-ItemProperty $NoStatic -Name NoStaticDefaultVerb)) {
  266. New-ItemProperty $NoStatic -Name NoStaticDefaultVerb -Verbose -ErrorAction SilentlyContinue
  267. }
  268. #Appends an underscore '_' to the Registry key for Edge
  269. $Edge = 'HKCR:\AppXd4nrz8ff68srnhf9t5a8sbjyar1cr723'
  270. If (Test-Path $Edge) {
  271. Set-Item $Edge AppXd4nrz8ff68srnhf9t5a8sbjyar1cr723_ -Verbose
  272. }
  273. }
  274. }
  275. Function FixWhitelistedApps {
  276. Param([switch]$Debloat, [switch]$SysPrep)
  277. IF ($Debloat -or $SysPrep) {
  278. Write-Verbose -Message ('Starting Fix Whitelisted Apps')
  279. If (!(Get-AppxPackage -AllUsers | Select Microsoft.Paint3D, Microsoft.WindowsCalculator, Microsoft.WindowsStore, Microsoft.Windows.Photos)) {
  280. #Credit to abulgatz for the 4 lines of code
  281. Get-AppxPackage -allusers Microsoft.Paint3D | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
  282. Get-AppxPackage -allusers Microsoft.WindowsCalculator | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
  283. Get-AppxPackage -allusers Microsoft.WindowsStore | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
  284. Get-AppxPackage -allusers Microsoft.Windows.Photos | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
  285. }
  286. }
  287. }
  288. Write-Output "Initiating Sysprep"
  289. Begin-SysPrep @PSBoundParameters
  290. Write-Output "Removing bloatware apps."
  291. Start-Debloat @PSBoundParameters
  292. Write-Output "Removing leftover bloatware registry keys."
  293. Remove-Keys @PSBoundParameters
  294. Write-Output "Checking to see if any Whitelisted Apps were removed, and if so re-adding them."
  295. FixWhitelistedApps @PSBoundParameters
  296. Write-Output "Stopping telemetry, disabling unneccessary scheduled tasks, and preventing bloatware from returning."
  297. Protect-Privacy @PSBoundParameters
  298. Write-Output "Stopping Edge from taking over as the default PDF Viewer."
  299. Stop-EdgePDF @PSBoundParameters
  300. Write-Output "Finished all tasks."