Windows10Debloater.ps1 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  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. #Checks for the script running as admin and if it's not then restarts the script in admin
  4. Add-Type -AssemblyName PresentationCore,PresentationFramework
  5. If (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]'Administrator')) {
  6. Start-Process powershell.exe -ArgumentList ("-NoProfile -ExecutionPolicy Bypass -File `"{0}`"" -f $PSCommandPath) -Verb RunAs
  7. Exit
  8. }
  9. If (Test-Path "C:\Windows10Debloater") {
  10. Write-Output "C:\Windows10Debloater exists. Skipping."
  11. }
  12. Else {
  13. Write-Output "The folder 'C:\Windows10Debloater' doesn't exist. This folder will be used for storing logs created after the script runs. Creating now."
  14. Start-Sleep 1
  15. New-Item -Path "C:\Windows10Debloater" -ItemType Directory
  16. }
  17. Start-Transcript -OutputDirectory "C:\Windows10Debloater"
  18. #no errors throughout
  19. $ErrorActionPreference = 'silentlycontinue'
  20. Function Start-Debloat {
  21. [CmdletBinding()]
  22. Param()
  23. #Removes AppxPackages
  24. #Credit to /u/GavinEke for a modified version of my whitelist code
  25. [regex]$WhitelistedApps = 'Microsoft.Paint3D|Microsoft.WindowsCalculator|Microsoft.WindowsStore|Microsoft.Windows.Photos|CanonicalGroupLimited.UbuntuonWindows|Microsoft.XboxGameCallableUI|Microsoft.XboxGamingOverlay|Microsoft.Xbox.TCUI|Microsoft.XboxGamingOverlay|Microsoft.XboxIdentityProvider'
  26. Get-AppxPackage -AllUsers | Where-Object {$_.Name -NotMatch $WhitelistedApps} | Remove-AppxPackage
  27. Get-AppxProvisionedPackage -Online | Where-Object {$_.PackageName -NotMatch $WhitelistedApps} | Remove-AppxProvisionedPackage -Online
  28. }
  29. Function Remove-Keys {
  30. [CmdletBinding()]
  31. Param()
  32. #These are the registry keys that it will delete.
  33. $Keys = @(
  34. #Remove Background Tasks
  35. "HKCR:\Extensions\ContractId\Windows.BackgroundTasks\PackageId\46928bounde.EclipseManager_2.2.4.51_neutral__a5h4egax66k6y"
  36. "HKCR:\Extensions\ContractId\Windows.BackgroundTasks\PackageId\ActiproSoftwareLLC.562882FEEB491_2.6.18.18_neutral__24pqs290vpjk0"
  37. "HKCR:\Extensions\ContractId\Windows.BackgroundTasks\PackageId\Microsoft.MicrosoftOfficeHub_17.7909.7600.0_x64__8wekyb3d8bbwe"
  38. "HKCR:\Extensions\ContractId\Windows.BackgroundTasks\PackageId\Microsoft.PPIProjection_10.0.15063.0_neutral_neutral_cw5n1h2txyewy"
  39. "HKCR:\Extensions\ContractId\Windows.BackgroundTasks\PackageId\Microsoft.XboxGameCallableUI_1000.15063.0.0_neutral_neutral_cw5n1h2txyewy"
  40. "HKCR:\Extensions\ContractId\Windows.BackgroundTasks\PackageId\Microsoft.XboxGameCallableUI_1000.16299.15.0_neutral_neutral_cw5n1h2txyewy"
  41. #Windows File
  42. "HKCR:\Extensions\ContractId\Windows.File\PackageId\ActiproSoftwareLLC.562882FEEB491_2.6.18.18_neutral__24pqs290vpjk0"
  43. #Registry keys to delete if they aren't uninstalled by RemoveAppXPackage/RemoveAppXProvisionedPackage
  44. "HKCR:\Extensions\ContractId\Windows.Launch\PackageId\46928bounde.EclipseManager_2.2.4.51_neutral__a5h4egax66k6y"
  45. "HKCR:\Extensions\ContractId\Windows.Launch\PackageId\ActiproSoftwareLLC.562882FEEB491_2.6.18.18_neutral__24pqs290vpjk0"
  46. "HKCR:\Extensions\ContractId\Windows.Launch\PackageId\Microsoft.PPIProjection_10.0.15063.0_neutral_neutral_cw5n1h2txyewy"
  47. "HKCR:\Extensions\ContractId\Windows.Launch\PackageId\Microsoft.XboxGameCallableUI_1000.15063.0.0_neutral_neutral_cw5n1h2txyewy"
  48. "HKCR:\Extensions\ContractId\Windows.Launch\PackageId\Microsoft.XboxGameCallableUI_1000.16299.15.0_neutral_neutral_cw5n1h2txyewy"
  49. #Scheduled Tasks to delete
  50. "HKCR:\Extensions\ContractId\Windows.PreInstalledConfigTask\PackageId\Microsoft.MicrosoftOfficeHub_17.7909.7600.0_x64__8wekyb3d8bbwe"
  51. #Windows Protocol Keys
  52. "HKCR:\Extensions\ContractId\Windows.Protocol\PackageId\ActiproSoftwareLLC.562882FEEB491_2.6.18.18_neutral__24pqs290vpjk0"
  53. "HKCR:\Extensions\ContractId\Windows.Protocol\PackageId\Microsoft.PPIProjection_10.0.15063.0_neutral_neutral_cw5n1h2txyewy"
  54. "HKCR:\Extensions\ContractId\Windows.Protocol\PackageId\Microsoft.XboxGameCallableUI_1000.15063.0.0_neutral_neutral_cw5n1h2txyewy"
  55. "HKCR:\Extensions\ContractId\Windows.Protocol\PackageId\Microsoft.XboxGameCallableUI_1000.16299.15.0_neutral_neutral_cw5n1h2txyewy"
  56. #Windows Share Target
  57. "HKCR:\Extensions\ContractId\Windows.ShareTarget\PackageId\ActiproSoftwareLLC.562882FEEB491_2.6.18.18_neutral__24pqs290vpjk0"
  58. )
  59. #This writes the output of each key it is removing and also removes the keys listed above.
  60. ForEach ($Key in $Keys) {
  61. Write-Output "Removing $Key from registry"
  62. Remove-Item $Key -Recurse
  63. }
  64. }
  65. Function Protect-Privacy {
  66. [CmdletBinding()]
  67. Param()
  68. #Disables Windows Feedback Experience
  69. Write-Output "Disabling Windows Feedback Experience program"
  70. $Advertising = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AdvertisingInfo"
  71. If (Test-Path $Advertising) {
  72. Set-ItemProperty $Advertising Enabled -Value 0 -Verbose
  73. }
  74. #Stops Cortana from being used as part of your Windows Search Function
  75. Write-Output "Stopping Cortana from being used as part of your Windows Search Function"
  76. $Search = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Windows Search"
  77. If (Test-Path $Search) {
  78. Set-ItemProperty $Search AllowCortana -Value 0 -Verbose
  79. }
  80. #Disables Web Search in Start Menu
  81. Write-Output "Disabling Bing Search in Start Menu"
  82. $WebSearch = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Windows Search"
  83. Set-ItemProperty "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Search" BingSearchEnabled -Value 0 -Verbose
  84. If (!(Test-Path $WebSearch)) {
  85. New-Item $WebSearch
  86. }
  87. Set-ItemProperty $WebSearch DisableWebSearch -Value 1 -Verbose
  88. #Stops the Windows Feedback Experience from sending anonymous data
  89. Write-Output "Stopping the Windows Feedback Experience program"
  90. $Period = "HKCU:\Software\Microsoft\Siuf\Rules"
  91. If (!(Test-Path $Period)) {
  92. New-Item $Period
  93. }
  94. Set-ItemProperty $Period PeriodInNanoSeconds -Value 0 -Verbose
  95. #Prevents bloatware applications from returning and removes Start Menu suggestions
  96. Write-Output "Adding Registry key to prevent bloatware apps from returning"
  97. $registryPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\CloudContent"
  98. $registryOEM = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager"
  99. If (!(Test-Path $registryPath)) {
  100. New-Item $registryPath
  101. }
  102. Set-ItemProperty $registryPath DisableWindowsConsumerFeatures -Value 1 -Verbose
  103. If (!(Test-Path $registryOEM)) {
  104. New-Item $registryOEM
  105. }
  106. Set-ItemProperty $registryOEM ContentDeliveryAllowed -Value 0 -Verbose
  107. Set-ItemProperty $registryOEM OemPreInstalledAppsEnabled -Value 0 -Verbose
  108. Set-ItemProperty $registryOEM PreInstalledAppsEnabled -Value 0 -Verbose
  109. Set-ItemProperty $registryOEM PreInstalledAppsEverEnabled -Value 0 -Verbose
  110. Set-ItemProperty $registryOEM SilentInstalledAppsEnabled -Value 0 -Verbose
  111. Set-ItemProperty $registryOEM SystemPaneSuggestionsEnabled -Value 0 -Verbose
  112. #Preping mixed Reality Portal for removal
  113. Write-Output "Setting Mixed Reality Portal value to 0 so that you can uninstall it in Settings"
  114. $Holo = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Holographic"
  115. If (Test-Path $Holo) {
  116. Set-ItemProperty $Holo FirstRunSucceeded -Value 0 -Verbose
  117. }
  118. #Disables Wi-fi Sense
  119. Write-Output "Disabling Wi-Fi Sense"
  120. $WifiSense1 = "HKLM:\SOFTWARE\Microsoft\PolicyManager\default\WiFi\AllowWiFiHotSpotReporting"
  121. $WifiSense2 = "HKLM:\SOFTWARE\Microsoft\PolicyManager\default\WiFi\AllowAutoConnectToWiFiSenseHotspots"
  122. $WifiSense3 = "HKLM:\SOFTWARE\Microsoft\WcmSvc\wifinetworkmanager\config"
  123. If (!(Test-Path $WifiSense1)) {
  124. New-Item $WifiSense1
  125. }
  126. Set-ItemProperty $WifiSense1 Value -Value 0 -Verbose
  127. If (!(Test-Path $WifiSense2)) {
  128. New-Item $WifiSense2
  129. }
  130. Set-ItemProperty $WifiSense2 Value -Value 0 -Verbose
  131. Set-ItemProperty $WifiSense3 AutoConnectAllowedOEM -Value 0 -Verbose
  132. #Disables live tiles
  133. Write-Output "Disabling live tiles"
  134. $Live = "HKCU:\SOFTWARE\Policies\Microsoft\Windows\CurrentVersion\PushNotifications"
  135. If (!(Test-Path $Live)) {
  136. New-Item $Live
  137. }
  138. Set-ItemProperty $Live NoTileApplicationNotification -Value 1 -Verbose
  139. #Turns off Data Collection via the AllowTelemtry key by changing it to 0
  140. Write-Output "Turning off Data Collection"
  141. $DataCollection1 = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection"
  142. $DataCollection2 = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection"
  143. $DataCollection3 = "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Policies\DataCollection"
  144. If (Test-Path $DataCollection1) {
  145. Set-ItemProperty $DataCollection1 AllowTelemetry -Value 0 -Verbose
  146. }
  147. If (Test-Path $DataCollection2) {
  148. Set-ItemProperty $DataCollection2 AllowTelemetry -Value 0 -Verbose
  149. }
  150. If (Test-Path $DataCollection3) {
  151. Set-ItemProperty $DataCollection3 AllowTelemetry -Value 0 -Verbose
  152. }
  153. #Disabling Location Tracking
  154. Write-Output "Disabling Location Tracking"
  155. $SensorState = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Sensor\Overrides\{BFA794E4-F964-4FDB-90F6-51056BFE4B44}"
  156. $LocationConfig = "HKLM:\SYSTEM\CurrentControlSet\Services\lfsvc\Service\Configuration"
  157. If (!(Test-Path $SensorState)) {
  158. New-Item $SensorState
  159. }
  160. Set-ItemProperty $SensorState SensorPermissionState -Value 0 -Verbose
  161. If (!(Test-Path $LocationConfig)) {
  162. New-Item $LocationConfig
  163. }
  164. Set-ItemProperty $LocationConfig Status -Value 0 -Verbose
  165. #Disables People icon on Taskbar
  166. Write-Output "Disabling People icon on Taskbar"
  167. $People = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\People"
  168. If (!(Test-Path $People)) {
  169. New-Item $People
  170. }
  171. Set-ItemProperty $People PeopleBand -Value 0 -Verbose
  172. #Disables scheduled tasks that are considered unnecessary
  173. Write-Output "Disabling scheduled tasks"
  174. Get-ScheduledTask XblGameSaveTaskLogon | Disable-ScheduledTask
  175. Get-ScheduledTask XblGameSaveTask | Disable-ScheduledTask
  176. Get-ScheduledTask Consolidator | Disable-ScheduledTask
  177. Get-ScheduledTask UsbCeip | Disable-ScheduledTask
  178. Get-ScheduledTask DmClient | Disable-ScheduledTask
  179. Get-ScheduledTask DmClientOnScenarioDownload | Disable-ScheduledTask
  180. }
  181. Function DisableCortana {
  182. Write-Host "Disabling Cortana"
  183. $Cortana1 = "HKCU:\SOFTWARE\Microsoft\Personalization\Settings"
  184. $Cortana2 = "HKCU:\SOFTWARE\Microsoft\InputPersonalization"
  185. $Cortana3 = "HKCU:\SOFTWARE\Microsoft\InputPersonalization\TrainedDataStore"
  186. If (!(Test-Path $Cortana1)) {
  187. New-Item $Cortana1
  188. }
  189. Set-ItemProperty $Cortana1 AcceptedPrivacyPolicy -Value 0 -Verbose
  190. If (!(Test-Path $Cortana2)) {
  191. New-Item $Cortana2
  192. }
  193. Set-ItemProperty $Cortana2 RestrictImplicitTextCollection -Value 1 -Verbose
  194. Set-ItemProperty $Cortana2 RestrictImplicitInkCollection -Value 1 -Verbose
  195. If (!(Test-Path $Cortana3)) {
  196. New-Item $Cortana3
  197. }
  198. Set-ItemProperty $Cortana3 HarvestContacts -Value 0 -Verbose
  199. }
  200. Function EnableCortana {
  201. Write-Host "Re-enabling Cortana"
  202. $Cortana1 = "HKCU:\SOFTWARE\Microsoft\Personalization\Settings"
  203. $Cortana2 = "HKCU:\SOFTWARE\Microsoft\InputPersonalization"
  204. $Cortana3 = "HKCU:\SOFTWARE\Microsoft\InputPersonalization\TrainedDataStore"
  205. If (!(Test-Path $Cortana1)) {
  206. New-Item $Cortana1
  207. }
  208. Set-ItemProperty $Cortana1 AcceptedPrivacyPolicy -Value 1 -Verbose
  209. If (!(Test-Path $Cortana2)) {
  210. New-Item $Cortana2
  211. }
  212. Set-ItemProperty $Cortana2 RestrictImplicitTextCollection -Value 0 -Verbose
  213. Set-ItemProperty $Cortana2 RestrictImplicitInkCollection -Value 0 -Verbose
  214. If (!(Test-Path $Cortana3)) {
  215. New-Item $Cortana3
  216. }
  217. Set-ItemProperty $Cortana3 HarvestContacts -Value 1 -Verbose
  218. }
  219. Function Stop-EdgePDF {
  220. #Stops edge from taking over as the default .PDF viewer
  221. Write-Output "Stopping Edge from taking over as the default .PDF viewer"
  222. $NoPDF = "HKCR:\.pdf"
  223. $NoProgids = "HKCR:\.pdf\OpenWithProgids"
  224. $NoWithList = "HKCR:\.pdf\OpenWithList"
  225. If (!(Get-ItemProperty $NoPDF NoOpenWith)) {
  226. New-ItemProperty $NoPDF NoOpenWith -Verbose
  227. }
  228. If (!(Get-ItemProperty $NoPDF NoStaticDefaultVerb)) {
  229. New-ItemProperty $NoPDF NoStaticDefaultVerb -Verbose
  230. }
  231. If (!(Get-ItemProperty $NoProgids NoOpenWith)) {
  232. New-ItemProperty $NoProgids NoOpenWith -Verbose
  233. }
  234. If (!(Get-ItemProperty $NoProgids NoStaticDefaultVerb)) {
  235. New-ItemProperty $NoProgids NoStaticDefaultVerb -Verbose
  236. }
  237. If (!(Get-ItemProperty $NoWithList NoOpenWith)) {
  238. New-ItemProperty $NoWithList NoOpenWith -Verbose
  239. }
  240. If (!(Get-ItemProperty $NoWithList NoStaticDefaultVerb)) {
  241. New-ItemProperty $NoWithList NoStaticDefaultVerb -Verbose
  242. }
  243. #Appends an underscore '_' to the Registry key for Edge
  244. $Edge = "HKCR:\AppXd4nrz8ff68srnhf9t5a8sbjyar1cr723_"
  245. If (Test-Path $Edge) {
  246. Set-Item $Edge AppXd4nrz8ff68srnhf9t5a8sbjyar1cr723_ -Verbose
  247. }
  248. }
  249. Function Revert-Changes {
  250. [CmdletBinding()]
  251. Param()
  252. #This function will revert the changes you made when running the Start-Debloat function.
  253. #This line reinstalls all of the bloatware that was removed
  254. Get-AppxPackage -AllUsers | ForEach {Add-AppxPackage -Verbose -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
  255. #Tells Windows to enable your advertising information.
  256. Write-Output "Re-enabling key to show advertisement information"
  257. $Advertising = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AdvertisingInfo"
  258. If (Test-Path $Advertising) {
  259. Set-ItemProperty $Advertising Enabled -Value 1 -Verbose
  260. }
  261. #Enables Cortana to be used as part of your Windows Search Function
  262. Write-Output "Re-enabling Cortana to be used in your Windows Search"
  263. $Search = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Windows Search"
  264. If (Test-Path $Search) {
  265. Set-ItemProperty $Search AllowCortana -Value 1 -Verbose
  266. }
  267. #Re-enables the Windows Feedback Experience for sending anonymous data
  268. Write-Output "Re-enabling Windows Feedback Experience"
  269. $Period = "HKCU:\Software\Microsoft\Siuf\Rules"
  270. If (!(Test-Path $Period)) {
  271. New-Item $Period
  272. }
  273. Set-ItemProperty $Period PeriodInNanoSeconds -Value 1 -Verbose
  274. #Enables bloatware applications
  275. Write-Output "Adding Registry key to allow bloatware apps to return"
  276. $registryPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\CloudContent"
  277. If (!(Test-Path $registryPath)) {
  278. New-Item $registryPath
  279. }
  280. Set-ItemProperty $registryPath DisableWindowsConsumerFeatures -Value 0 -Verbose
  281. #Changes Mixed Reality Portal Key 'FirstRunSucceeded' to 1
  282. Write-Output "Setting Mixed Reality Portal value to 1"
  283. $Holo = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Holographic"
  284. If (Test-Path $Holo) {
  285. Set-ItemProperty $Holo FirstRunSucceeded -Value 1 -Verbose
  286. }
  287. #Re-enables live tiles
  288. Write-Output "Enabling live tiles"
  289. $Live = "HKCU:\SOFTWARE\Policies\Microsoft\Windows\CurrentVersion\PushNotifications"
  290. If (!(Test-Path $Live)) {
  291. New-Item $Live
  292. }
  293. Set-ItemProperty $Live NoTileApplicationNotification -Value 0 -Verbose
  294. #Re-enables data collection
  295. Write-Output "Re-enabling data collection"
  296. $DataCollection = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection"
  297. If (!(Test-Path $DataCollection)) {
  298. New-Item $DataCollection
  299. }
  300. Set-ItemProperty $DataCollection AllowTelemetry -Value 1 -Verbose
  301. #Re-enables People Icon on Taskbar
  302. Write-Output "Enabling People icon on Taskbar"
  303. $People = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\People"
  304. If (!(Test-Path $People)) {
  305. New-Item $People
  306. }
  307. Set-ItemProperty $People PeopleBand -Value 1 -Verbose
  308. #Re-enables suggestions on start menu
  309. Write-Output "Enabling suggestions on the Start Menu"
  310. $Suggestions = "HKCU:\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager"
  311. If (!(Test-Path $Suggestions)) {
  312. New-Item $Suggestions
  313. }
  314. Set-ItemProperty $Suggestions SystemPaneSuggestionsEnabled -Value 1 -Verbose
  315. #Re-enables scheduled tasks that were disabled when running the Debloat switch
  316. Write-Output "Enabling scheduled tasks that were disabled"
  317. Get-ScheduledTask XblGameSaveTaskLogon | Enable-ScheduledTask
  318. Get-ScheduledTask XblGameSaveTask | Enable-ScheduledTask
  319. Get-ScheduledTask Consolidator | Enable-ScheduledTask
  320. Get-ScheduledTask UsbCeip | Enable-ScheduledTask
  321. Get-ScheduledTask DmClient | Enable-ScheduledTask
  322. Get-ScheduledTask DmClientOnScenarioDownload | Enable-ScheduledTask
  323. }
  324. Function Enable-EdgePDF {
  325. Write-Output "Setting Edge back to default"
  326. $NoPDF = "HKCR:\.pdf"
  327. $NoProgids = "HKCR:\.pdf\OpenWithProgids"
  328. $NoWithList = "HKCR:\.pdf\OpenWithList"
  329. #Sets edge back to default
  330. If (Get-ItemProperty $NoPDF NoOpenWith) {
  331. Remove-ItemProperty $NoPDF NoOpenWith -Verbose
  332. }
  333. If (Get-ItemProperty $NoPDF NoStaticDefaultVerb) {
  334. Remove-ItemProperty $NoPDF NoStaticDefaultVerb -Verbose
  335. }
  336. If (Get-ItemProperty $NoProgids NoOpenWith) {
  337. Remove-ItemProperty $NoProgids NoOpenWith -Verbose
  338. }
  339. If (Get-ItemProperty $NoProgids NoStaticDefaultVerb) {
  340. Remove-ItemProperty $NoProgids NoStaticDefaultVerb -Verbose
  341. }
  342. If (Get-ItemProperty $NoWithList NoOpenWith) {
  343. Remove-ItemProperty $NoWithList NoOpenWith -Verbose
  344. }
  345. If (Get-ItemProperty $NoWithList NoStaticDefaultVerb) {
  346. Remove-ItemProperty $NoWithList NoStaticDefaultVerb -Verbose
  347. }
  348. #Removes an underscore '_' from the Registry key for Edge
  349. $Edge2 = "HKCR:\AppXd4nrz8ff68srnhf9t5a8sbjyar1cr723_"
  350. If (Test-Path $Edge2) {
  351. Set-Item $Edge2 AppXd4nrz8ff68srnhf9t5a8sbjyar1cr723 -Verbose
  352. }
  353. }
  354. Function FixWhitelistedApps {
  355. [CmdletBinding()]
  356. Param()
  357. If (!(Get-AppxPackage -AllUsers | Select Microsoft.Paint3D, Microsoft.WindowsCalculator, Microsoft.WindowsStore, Microsoft.Windows.Photos)) {
  358. #Credit to abulgatz for these 4 lines of code
  359. Get-AppxPackage -allusers Microsoft.Paint3D | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
  360. Get-AppxPackage -allusers Microsoft.WindowsCalculator | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
  361. Get-AppxPackage -allusers Microsoft.WindowsStore | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
  362. Get-AppxPackage -allusers Microsoft.Windows.Photos | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
  363. }
  364. }
  365. Function DisableDiagTrack {
  366. Write-Output "Stopping and disabling Diagnostics Tracking Service"
  367. #Disabling the Diagnostics Tracking Service
  368. Stop-Service "DiagTrack"
  369. Set-Service "DiagTrack" -StartupType Disabled
  370. }
  371. Function EnableDiagTrack {
  372. Write-Output "Re-enabling and starting the Diagnostics Tracking Service"
  373. #Enabling the Diagnostics Tracking Service
  374. Set-Service "DiagTrack" -StartupType Automatic
  375. Start-Service "DiagTrack"
  376. }
  377. Function DisableWAPPush {
  378. Write-Output "Stopping and disabling WAP Push Service"
  379. #Stop and disable WAP Push Service
  380. Stop-Service "dmwappushservice"
  381. Set-Service "dmwappushservice" -StartupType Disabled
  382. }
  383. Function EnableWAPPush {
  384. Write-Output "Re-enabling and starting WAP Push Service"
  385. #Enable and start WAP Push Service
  386. Set-Service "dmwappushservice" -StartupType Automatic
  387. Start-Service "dmwappushservice"
  388. }
  389. Function UninstallOneDrive {
  390. Write-Output "Uninstalling OneDrive"
  391. $onedrive = "$env:SYSTEMROOT\SysWOW64\OneDriveSetup.exe"
  392. $ExplorerReg1 = "HKCR:\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}"
  393. $ExplorerReg2 = "HKCR:\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}"
  394. Stop-Process OneDrive
  395. Start-Sleep 2
  396. If (!(Test-Path $onedrive)) {
  397. $onedrive = "$env:SYSTEMROOT\System32\OneDriveSetup.exe"
  398. }
  399. Start-Process $onedrive "/uninstall" -NoNewWindow -Wait
  400. Start-Sleep 2
  401. Write-Output "Stopping explorer"
  402. Start-Sleep 1
  403. .\taskkill.exe /F /IM explorer.exe
  404. Start-Sleep 3
  405. Write-Output "Removing leftover files"
  406. Remove-Item "$env:USERPROFILE\OneDrive" -Force -Recurse
  407. Remove-Item "$env:LOCALAPPDATA\Microsoft\OneDrive" -Force -Recurse
  408. Remove-Item "$env:PROGRAMDATA\Microsoft OneDrive" -Force -Recurse
  409. If (Test-Path "$env:SYSTEMDRIVE\OneDriveTemp") {
  410. Remove-Item "$env:SYSTEMDRIVE\OneDriveTemp" -Force -Recurse
  411. }
  412. Write-Output "Removing OneDrive from windows explorer"
  413. If (!(Test-Path $ExplorerReg1)) {
  414. New-Item $ExplorerReg1
  415. }
  416. Set-ItemProperty $ExplorerReg1 System.IsPinnedToNameSpaceTree -Value 0 -Verbose
  417. If (!(Test-Path $ExplorerReg2)) {
  418. New-Item $ExplorerReg2
  419. }
  420. Set-ItemProperty $ExplorerReg2 System.IsPinnedToNameSpaceTree -Value 0 -Verbose
  421. Write-Output "Restarting Explorer that was shut down before."
  422. Start explorer.exe -NoNewWindow
  423. }
  424. #GUI prompt Debloat/Revert options and GUI variables
  425. $Button = [Windows.MessageBoxButton]::YesNoCancel
  426. $ErrorIco = [Windows.MessageBoxImage]::Error
  427. $Warn = [Windows.MessageBoxImage]::Warning
  428. $Ask = 'The following will allow you to either Debloat Windows 10 or to revert changes made after Debloating Windows 10.
  429. Select "Yes" to Debloat Windows 10
  430. Select "No" to Revert changes made by this script
  431. Select "Cancel" to stop the script.'
  432. $EdgePdf = "Do you want to stop edge from taking over as the default PDF viewer?"
  433. $EdgePdf2 = "Do you want to revert changes that disabled Edge as the default PDF viewer?"
  434. $Reboot = "For some of the changes to properly take effect it is recommended to reboot your machine. Would you like to restart?"
  435. $OneDriveDelete = "Do you want to uninstall One Drive?"
  436. $Prompt1 = [Windows.MessageBox]::Show($Ask,"Debloat or Revert",$Button,$ErrorIco)
  437. Switch ($Prompt1) {
  438. #This will debloat Windows 10
  439. Yes {
  440. #Creates a "drive" to access the HKCR (HKEY_CLASSES_ROOT)
  441. Write-Output "Creating PSDrive 'HKCR' (HKEY_CLASSES_ROOT). This will be used for the duration of the script as it is necessary for the removal and modification of specific registry keys."
  442. New-PSDrive HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT
  443. Start-Sleep 1
  444. Write-Output "Uninstalling bloatware, please wait."
  445. Start-Debloat
  446. Write-Output "Bloatware removed."
  447. Start-Sleep 1
  448. Write-Output "Removing specific registry keys."
  449. Remove-Keys
  450. Write-Output "Leftover bloatware registry keys removed."
  451. Start-Sleep 1
  452. Write-Output "Checking to see if any Whitelisted Apps were removed, and if so re-adding them."
  453. Start-Sleep 1
  454. FixWhitelistedApps
  455. Start-Sleep 1
  456. Write-Output "Disabling Cortana from search, disabling feedback to Microsoft, and disabling scheduled tasks that are considered to be telemetry or unnecessary."
  457. Protect-Privacy
  458. Start-Sleep 1
  459. DisableCortana
  460. Write-Output "Cortana disabled and removed from search, feedback to Microsoft has been disabled, and scheduled tasks are disabled."
  461. Start-Sleep 1
  462. Write-Output "Stopping and disabling Diagnostics Tracking Service"
  463. DisableDiagTrack
  464. Write-Output "Diagnostics Tracking Service disabled"
  465. Start-Sleep 1
  466. Write-Output "Disabling WAP push service"
  467. Start-Sleep 1
  468. DisableWAPPush
  469. Write-Output "WAP push service stopped and disabled"
  470. Start-Sleep 1; $PublishSettings = $Debloat
  471. $Prompt2 = [Windows.MessageBox]::Show($EdgePdf,"Edge PDF",$Button,$Warn)
  472. Switch ($Prompt2) {
  473. Yes {
  474. Stop-EdgePDF
  475. Write-Output "Edge will no longer take over as the default PDF viewer."; $PublishSettings = $Yes
  476. }
  477. No {
  478. $PublishSettings = $No
  479. }
  480. Cancel {
  481. Exit-PSSession
  482. }
  483. }
  484. #Prompt asking to delete OneDrive
  485. $Prompt3 = [Windows.MessageBox]::Show($OneDriveDelete,"Delete OneDrive",$Button,$ErrorIco)
  486. Switch ($Prompt3) {
  487. Yes {
  488. UninstallOneDrive
  489. Write-Output "OneDrive is now removed from the computer."; $PublishSettings = $Yes
  490. }
  491. No {
  492. $PublishSettings = $No
  493. }
  494. Cancel {
  495. Exit-PSSession
  496. }
  497. }
  498. #Prompt asking if you'd like to reboot your machine
  499. $Prompt4 = [Windows.MessageBox]::Show($Reboot,"Reboot",$Button,$Warn)
  500. Switch ($Prompt4) {
  501. Yes {
  502. Write-Output "Unloading the HKCR drive..."
  503. Remove-PSDrive HKCR
  504. Start-Sleep 1
  505. Stop-Transcript
  506. Write-Output "Initiating reboot."
  507. Start-Sleep 2
  508. Restart-Computer; $PublishSettings = $Yes
  509. }
  510. No {
  511. Write-Output "Unloading the HKCR drive..."
  512. Remove-PSDrive HKCR
  513. Start-Sleep 1
  514. Stop-Transcript
  515. Write-Output "Script has finished. Exiting."
  516. Start-Sleep 2
  517. Exit; $PublishSettings = $No
  518. }
  519. Cancel {
  520. Exit-PSSession
  521. }
  522. }
  523. }
  524. No {
  525. Write-Output "Reverting changes..."
  526. Write-Output "Creating PSDrive 'HKCR' (HKEY_CLASSES_ROOT). This will be used for the duration of the script as it is necessary for the modification of specific registry keys."
  527. New-PSDrive HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT
  528. Revert-Changes; $PublishSettings = $Revert
  529. #Prompt asking to revert edge changes as well
  530. $Prompt5 = [Windows.MessageBox]::Show($EdgePdf2,"Revert Edge",$Button,$ErrorIco)
  531. Switch ($Prompt5) {
  532. Yes {
  533. Enable-EdgePDF
  534. Write-Output "Edge will no longer be disabled from being used as the default Edge PDF viewer."; $PublishSettings = $Yes
  535. }
  536. No {$PublishSettings = $No
  537. }
  538. Cancel {
  539. Exit-PSSession
  540. }
  541. }
  542. #Prompt asking if you'd like to reboot your machine
  543. $Prompt6 = [Windows.MessageBox]::Show($Reboot,"Reboot",$Button,$Warn)
  544. Switch ($Prompt6) {
  545. Yes {
  546. Write-Output "Unloading the HKCR drive..."
  547. Remove-PSDrive HKCR
  548. Start-Sleep 1
  549. Write-Output "Initiating reboot."
  550. Stop-Transcript
  551. Start-Sleep 2
  552. Restart-Computer; $PublishSettings = $Yes
  553. }
  554. No {
  555. Write-Output "Unloading the HKCR drive..."
  556. Remove-PSDrive HKCR
  557. Start-Sleep 1
  558. Write-Output "Script has finished. Exiting."
  559. Stop-Transcript
  560. Start-Sleep 2
  561. Exit; $PublishSettings = $No
  562. }
  563. Cancel {
  564. Exit-PSSession
  565. }
  566. }
  567. }
  568. Cancel {
  569. Exit-PSSession
  570. }
  571. }