From fea116fd78137f65a2d60fa3c8cc15649f0f0a32 Mon Sep 17 00:00:00 2001 From: Damian Date: Wed, 27 Feb 2019 23:39:11 -0500 Subject: [PATCH 1/6] Fixed GUI errors and Admin Check Started out adding a new feature about removing 3D objects from explorer in This PC but I found a lot of code re use and found bugs when I went to add it to the GUI Fixed -Verbose being used where Write-Host is already being used. Fixed Admin check so it works, it was removed last year for some reason after I added it when I started adding my code to this project from my old debloat. Fixed some code reuse where -ErrorAction SilentlyContinue is called multiple times even after it's already a global settings set in the start of the function. Removed -Name from where it just wasn't needed to slim down file size. Fixed the OneDrive button so it workes without errors and finds everything the way it should. Shortened .NET 3.5 section to slim down file size Fixed Disable Windows Store Automatic Updates code so it runs without errors and is shorter. --- Windows10Debloater.ps1 | 48 ++++- Windows10DebloaterGUI.ps1 | 417 +++++++++++++++----------------------- 2 files changed, 204 insertions(+), 261 deletions(-) diff --git a/Windows10Debloater.ps1 b/Windows10Debloater.ps1 index cb9cd58..703fe29 100644 --- a/Windows10Debloater.ps1 +++ b/Windows10Debloater.ps1 @@ -2,12 +2,11 @@ #Also, to note - This does NOT remove essential system services/software/etc such as .NET framework installations, Cortana, Edge, etc. #This will self elevate the script so with a UAC prompt since this script needs to be run as an Administrator in order to function properly. -If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { - $arguments = "&" + $MyInvocation.MyCommand.Definition + "" - Write-Host "You didn't run this script as an Administrator. This script will self elevate to run as an Administrator." -ForegroundColor "White" - Start-Sleep 1 - Start-Process "powershell.exe" -Verb RunAs -ArgumentList $arguments - Break +If (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]'Administrator')) { + Write-Host "You didn't run this script as an Administrator. This script will self elevate to run as an Administrator and continue." + Start-Sleep 2 + Start-Process powershell.exe -ArgumentList ("-NoProfile -ExecutionPolicy Bypass -File `"{0}`"" -f $PSCommandPath) -Verb RunAs + Exit } #no errors throughout @@ -488,6 +487,10 @@ Function Revert-Changes { #Enabling the Diagnostics Tracking Service Set-Service "DiagTrack" -StartupType Automatic Start-Service "DiagTrack" + + Write-Output "Restoring 3D Objects in the 'My Computer' submenu in explorer" + #Restoring 3D Objects in the 'My Computer' submenu in explorer + Restore3dObjects } Function CheckDMWService { @@ -641,7 +644,33 @@ Function UnpinStart { %{$_.DoIt()} } -#GUI prompt Debloat/Revert options and GUI variables +Function Remove3dObjects { +#Removes 3D Objects from the 'My Computer' submenu in explorer + Write-Output "Removing 3D Objects from explorer 'My Computer' submenu" + $Objects32 = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{0DB7E03F-FC29-4DC6-9020-FF41B59E513A}" + $Objects64 = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{0DB7E03F-FC29-4DC6-9020-FF41B59E513A}" + If (Test-Path $Objects32) { + Remove-Item $Objects32 -Recurse + } + If (Test-Path $Objects64) { + Remove-Item $Objects64 -Recurse + } +} + +Function Restore3dObjects { +#Restores 3D Objects from the 'My Computer' submenu in explorer + Write-Output "Restoring 3D Objects from explorer 'My Computer' submenu" + $Objects32 = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{0DB7E03F-FC29-4DC6-9020-FF41B59E513A}" + $Objects64 = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{0DB7E03F-FC29-4DC6-9020-FF41B59E513A}" + If (!(Test-Path $Objects32)) { + New-Item $Objects32 + } + If (!(Test-Path $Objects64)) { + New-Item $Objects64 + } +} + +#Interactive prompt Debloat/Revert options $Button = [Windows.MessageBoxButton]::YesNoCancel $ErrorIco = [Windows.MessageBoxImage]::Error $Warn = [Windows.MessageBoxImage]::Warning @@ -695,11 +724,14 @@ Switch ($Prompt1) { Write-Output "Diagnostics Tracking Service disabled" Start-Sleep 1 Write-Output "Disabling WAP push service" - Start-Sleep 1 DisableWAPPush + Start-Sleep 1 Write-Output "Re-enabling DMWAppushservice if it was disabled" CheckDMWService Start-Sleep 1 + Write-Output "Removing 3D Objects from the 'My Computer' submenu in explorer" + Remove3dObjects + Start-Sleep 1 } No { #Creates a "drive" to access the HKCR (HKEY_CLASSES_ROOT) diff --git a/Windows10DebloaterGUI.ps1 b/Windows10DebloaterGUI.ps1 index 46aac1c..e7795a1 100644 --- a/Windows10DebloaterGUI.ps1 +++ b/Windows10DebloaterGUI.ps1 @@ -1,21 +1,16 @@ #This will self elevate the script so with a UAC prompt since this script needs to be run as an Administrator in order to function properly. -If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { - $arguments = "&" + $MyInvocation.MyCommand.Definition + "" - Write-Host "You didn't run this script as an Administrator. This script will self elevate to run as an Administrator." -ForegroundColor "White" - Start-Sleep 1 - Start-Process "powershell.exe" -Verb RunAs -ArgumentList $arguments - Break +If (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]'Administrator')) { + Write-Host "You didn't run this script as an Administrator. This script will self elevate to run as an Administrator and continue." + Start-Sleep 2 + Start-Process powershell.exe -ArgumentList ("-NoProfile -ExecutionPolicy Bypass -File `"{0}`"" -f $PSCommandPath) -Verb RunAs + Exit } -<# This form was created using POSHGUI.com a free online gui designer for PowerShell -.NAME - Untitled -#> +# This form was created using POSHGUI.com a free online gui designer for PowerShell Add-Type -AssemblyName System.Windows.Forms [System.Windows.Forms.Application]::EnableVisualStyles() -#region begin GUI{ - +#region begin GUI $Form = New-Object system.Windows.Forms.Form $Form.ClientSize = '408,523' $Form.text = "Windows10Debloater" @@ -148,13 +143,13 @@ $Form.controls.AddRange(@($Debloat, $RemoveAllBloatware, $RemoveBlacklist, $Labe $DebloatFolder = "C:\Temp\Windows10Debloater" If (Test-Path $DebloatFolder) { - Write-Output "$DebloatFolder exists. Skipping." + Write-Host "$DebloatFolder exists. Skipping." } Else { - Write-Output "The folder "$DebloatFolder" doesn't exist. This folder will be used for storing logs created after the script runs. Creating now." + Write-Host "The folder "$DebloatFolder" doesn't exist. This folder will be used for storing logs created after the script runs. Creating now." Start-Sleep 1 New-Item -Path "$DebloatFolder" -ItemType Directory - Write-Output "The folder $DebloatFolder was successfully created." + Write-Host "The folder $DebloatFolder was successfully created." } Start-Transcript -OutputDirectory "$DebloatFolder" @@ -234,10 +229,10 @@ $RemoveBlacklist.Add_Click( { #"*Microsoft.WindowsStore*" ) foreach ($Bloat in $Bloatware) { - Get-AppxPackage -Name $Bloat| Remove-AppxPackage -ErrorAction SilentlyContinue - Get-AppxProvisionedPackage -Online | Where-Object DisplayName -like $Bloat | Remove-AppxProvisionedPackage -Online -ErrorAction SilentlyContinue + Get-AppxPackage -Name $Bloat| Remove-AppxPackage + Get-AppxProvisionedPackage -Online | Where-Object DisplayName -like $Bloat | Remove-AppxProvisionedPackage -Online Write-Host "Trying to remove $Bloat." - Write-Host "Bloatware removed! `n" + Write-Host "Bloatware removed!" } } Write-Host "Removing Bloatware with a specific blacklist." @@ -253,39 +248,37 @@ $RemoveAllBloatware.Add_Click( { Function Begin-SysPrep { $ErrorActionPreference = 'silentlycontinue' - Write-Host -Message ('Starting Sysprep Fixes') + Write-Host "Starting Sysprep Fixes" # Disable Windows Store Automatic Updates - Write-Host -Message "Adding Registry key to Disable Windows Store Automatic Updates" + Write-Host "Adding Registry key to Disable Windows Store Automatic Updates" $registryPath = "HKLM:\SOFTWARE\Policies\Microsoft\WindowsStore" If (!(Test-Path $registryPath)) { - Mkdir $registryPath -ErrorAction SilentlyContinue - New-ItemProperty $registryPath -Name AutoDownload -Value 2 - } - Else { - Set-ItemProperty $registryPath -Name AutoDownload -Value 2 + Mkdir $registryPath + New-ItemProperty $registryPath AutoDownload -Value 2 } + Set-ItemProperty $registryPath AutoDownload -Value 2 + #Stop WindowsStore Installer Service and set to Disabled - Write-Host -Message ('Stopping InstallService') + Write-Host "Stopping InstallService" Stop-Service InstallService - Write-Host -Message ('Setting InstallService Startup to Disabled') - & Set-Service -Name InstallService -StartupType Disabled + Write-Host "Setting InstallService Startup to Disabled" + Set-Service InstallService -StartupType Disabled } Function CheckDMWService { Param([switch]$Debloat) - If (Get-Service -Name dmwappushservice | Where-Object {$_.StartType -eq "Disabled"}) { - Set-Service -Name dmwappushservice -StartupType Automatic + If (Get-Service dmwappushservice | Where-Object {$_.StartType -eq "Disabled"}) { + Set-Service dmwappushservice -StartupType Automatic } - If (Get-Service -Name dmwappushservice | Where-Object {$_.Status -eq "Stopped"}) { - Start-Service -Name dmwappushservice + If (Get-Service dmwappushservice | Where-Object {$_.Status -eq "Stopped"}) { + Start-Service dmwappushservice } } - Function DebloatAll { [CmdletBinding()] @@ -304,85 +297,8 @@ $RemoveAllBloatware.Add_Click( { #Creates a PSDrive to be able to access the 'HKCR' tree New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT - Function DebloatBlacklist { - $ErrorActionPreference = 'silentlycontinue' - - $Bloatware = @( - - #Unnecessary Windows 10 AppX Apps - "Microsoft.BingNews" - "Microsoft.GetHelp" - "Microsoft.Getstarted" - "Microsoft.Messaging" - "Microsoft.Microsoft3DViewer" - "Microsoft.MicrosoftOfficeHub" - "Microsoft.MicrosoftSolitaireCollection" - "Microsoft.NetworkSpeedTest" - "Microsoft.News" - "Microsoft.Office.Lens" - "Microsoft.Office.OneNote" - "Microsoft.Office.Sway" - "Microsoft.OneConnect" - "Microsoft.People" - "Microsoft.Print3D" - "Microsoft.RemoteDesktop" - "Microsoft.SkypeApp" - "Microsoft.StorePurchaseApp" - "Microsoft.Office.Todo.List" - "Microsoft.Whiteboard" - "Microsoft.WindowsAlarms" - #"Microsoft.WindowsCamera" - "microsoft.windowscommunicationsapps" - "Microsoft.WindowsFeedbackHub" - "Microsoft.WindowsMaps" - "Microsoft.WindowsSoundRecorder" - "Microsoft.Xbox.TCUI" - "Microsoft.XboxApp" - "Microsoft.XboxGameOverlay" - "Microsoft.XboxIdentityProvider" - "Microsoft.XboxSpeechToTextOverlay" - "Microsoft.ZuneMusic" - "Microsoft.ZuneVideo" - "*Windows.CBSPreview*" - - #Sponsored Windows 10 AppX Apps - #Add sponsored/featured apps to remove in the "*AppName*" format - "*EclipseManager*" - "*ActiproSoftwareLLC*" - "*AdobeSystemsIncorporated.AdobePhotoshopExpress*" - "*Duolingo-LearnLanguagesforFree*" - "*PandoraMediaInc*" - "*CandyCrush*" - "*Wunderlist*" - "*Flipboard*" - "*Twitter*" - "*Facebook*" - "*Spotify*" - "*Minecraft*" - "*Royal Revolt*" - "*Sway*" - "*Dolby*" - - #Optional: Typically not removed but you can if you need to for some reason - #"*Microsoft.Advertising.Xaml_10.1712.5.0_x64__8wekyb3d8bbwe*" - #"*Microsoft.Advertising.Xaml_10.1712.5.0_x86__8wekyb3d8bbwe*" - #"*Microsoft.BingWeather*" - #"*Microsoft.MSPaint*" - #"*Microsoft.MicrosoftStickyNotes*" - #"*Microsoft.Windows.Photos*" - #"*Microsoft.WindowsCalculator*" - #"*Microsoft.WindowsStore*" - ) - foreach ($Bloat in $Bloatware) { - Get-AppxPackage -Name $Bloat| Remove-AppxPackage -ErrorAction SilentlyContinue - Get-AppxProvisionedPackage -Online | Where-Object DisplayName -like $Bloat | Remove-AppxProvisionedPackage -Online -ErrorAction SilentlyContinue - Write-Host "Trying to remove $Bloat." - } - } - Function Remove-Keys { - $ErrorActionPreference = 'silentlycontinue' - + Function Remove-Keys { #These are the registry keys that it will delete. $Keys = @( @@ -421,12 +337,11 @@ $RemoveAllBloatware.Add_Click( { #This writes the output of each key it is removing and also removes the keys listed above. ForEach ($Key in $Keys) { Write-Host "Removing $Key from registry" - Remove-Item $Key -Recurse -ErrorAction SilentlyContinue + Remove-Item $Key -Recurse } } Function Protect-Privacy { - $ErrorActionPreference = 'silentlycontinue' #Creates a PSDrive to be able to access the 'HKCR' tree New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT @@ -435,14 +350,14 @@ $RemoveAllBloatware.Add_Click( { Write-Host "Disabling Windows Feedback Experience program" $Advertising = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AdvertisingInfo' If (Test-Path $Advertising) { - Set-ItemProperty $Advertising -Name Enabled -Value 0 -Verbose + Set-ItemProperty $Advertising Enabled -Value 0 } #Stops Cortana from being used as part of your Windows Search Function Write-Host "Stopping Cortana from being used as part of your Windows Search Function" $Search = 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\Windows Search' If (Test-Path $Search) { - Set-ItemProperty $Search -Name AllowCortana -Value 0 -Verbose + Set-ItemProperty $Search AllowCortana -Value 0 } #Stops the Windows Feedback Experience from sending anonymous data @@ -451,57 +366,57 @@ $RemoveAllBloatware.Add_Click( { $Period2 = 'HKCU:\Software\Microsoft\Siuf\Rules' $Period3 = 'HKCU:\Software\Microsoft\Siuf\Rules\PeriodInNanoSeconds' If (!(Test-Path $Period3)) { - mkdir $Period1 -ErrorAction SilentlyContinue - mkdir $Period2 -ErrorAction SilentlyContinue - mkdir $Period3 -ErrorAction SilentlyContinue - New-ItemProperty $Period3 -Name PeriodInNanoSeconds -Value 0 -Verbose -ErrorAction SilentlyContinue + mkdir $Period1 + mkdir $Period2 + mkdir $Period3 + New-ItemProperty $Period3 PeriodInNanoSeconds -Value 0 } Write-Host "Adding Registry key to prevent bloatware apps from returning" #Prevents bloatware applications from returning $registryPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\CloudContent" If (!(Test-Path $registryPath)) { - Mkdir $registryPath -ErrorAction SilentlyContinue - New-ItemProperty $registryPath -Name DisableWindowsConsumerFeatures -Value 1 -Verbose -ErrorAction SilentlyContinue + Mkdir $registryPath + New-ItemProperty $registryPath DisableWindowsConsumerFeatures -Value 1 } Write-Host "Setting Mixed Reality Portal value to 0 so that you can uninstall it in Settings" $Holo = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Holographic' If (Test-Path $Holo) { - Set-ItemProperty $Holo -Name FirstRunSucceeded -Value 0 -Verbose + Set-ItemProperty $Holo FirstRunSucceeded -Value 0 } #Disables live tiles Write-Host "Disabling live tiles" $Live = 'HKCU:\SOFTWARE\Policies\Microsoft\Windows\CurrentVersion\PushNotifications' If (!(Test-Path $Live)) { - mkdir $Live -ErrorAction SilentlyContinue - New-ItemProperty $Live -Name NoTileApplicationNotification -Value 1 -Verbose + mkdir $Live + New-ItemProperty $Live NoTileApplicationNotification -Value 1 } #Turns off Data Collection via the AllowTelemtry key by changing it to 0 Write-Host "Turning off Data Collection" $DataCollection = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection' If (Test-Path $DataCollection) { - Set-ItemProperty $DataCollection -Name AllowTelemetry -Value 0 -Verbose + Set-ItemProperty $DataCollection AllowTelemetry -Value 0 } #Disables People icon on Taskbar Write-Host "Disabling People icon on Taskbar" $People = 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\People' If (Test-Path $People) { - Set-ItemProperty $People -Name PeopleBand -Value 0 -Verbose + Set-ItemProperty $People PeopleBand -Value 0 } #Disables suggestions on start menu Write-Host "Disabling suggestions on the Start Menu" $Suggestions = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager' If (Test-Path $Suggestions) { - Set-ItemProperty $Suggestions -Name SystemPaneSuggestionsEnabled -Value 0 -Verbose + Set-ItemProperty $Suggestions SystemPaneSuggestionsEnabled -Value 0 } - Write-Output "Removing CloudStore from registry if it exists" + Write-Host "Removing CloudStore from registry if it exists" $CloudStore = 'HKCUSoftware\Microsoft\Windows\CurrentVersion\CloudStore' If (Test-Path $CloudStore) { Stop-Process Explorer.exe -Force @@ -518,15 +433,15 @@ $RemoveAllBloatware.Add_Click( { #Disables scheduled tasks that are considered unnecessary Write-Host "Disabling scheduled tasks" - #Get-ScheduledTask -TaskName XblGameSaveTaskLogon | Disable-ScheduledTask -ErrorAction SilentlyContinue - Get-ScheduledTask -TaskName XblGameSaveTask | Disable-ScheduledTask -ErrorAction SilentlyContinue - Get-ScheduledTask -TaskName Consolidator | Disable-ScheduledTask -ErrorAction SilentlyContinue - Get-ScheduledTask -TaskName UsbCeip | Disable-ScheduledTask -ErrorAction SilentlyContinue - Get-ScheduledTask -TaskName DmClient | Disable-ScheduledTask -ErrorAction SilentlyContinue - Get-ScheduledTask -TaskName DmClientOnScenarioDownload | Disable-ScheduledTask -ErrorAction SilentlyContinue + #Get-ScheduledTask -TaskName XblGameSaveTaskLogon | Disable-ScheduledTask + Get-ScheduledTask -TaskName XblGameSaveTask | Disable-ScheduledTask + Get-ScheduledTask -TaskName Consolidator | Disable-ScheduledTask + Get-ScheduledTask -TaskName UsbCeip | Disable-ScheduledTask + Get-ScheduledTask -TaskName DmClient | Disable-ScheduledTask + Get-ScheduledTask -TaskName DmClientOnScenarioDownload | Disable-ScheduledTask } - Function UnpinStart { + Function UnpinStart { #Credit to Vikingat-Rage #https://superuser.com/questions/1068382/how-to-remove-all-the-tiles-in-the-windows-10-start-menu #Unpins all tiles from the Start Menu @@ -538,6 +453,19 @@ $RemoveAllBloatware.Add_Click( { ?{$_.Name -match 'Un.*pin from Start'} | %{$_.DoIt()} } + + Function Remove3dObjects { + #Removes 3D Objects from the 'My Computer' submenu in explorer + Write-Output "Removing 3D Objects from explorer 'My Computer' submenu" + $Objects32 = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{0DB7E03F-FC29-4DC6-9020-FF41B59E513A}" + $Objects64 = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{0DB7E03F-FC29-4DC6-9020-FF41B59E513A}" + If (Test-Path $Objects32) { + Remove-Item $Objects32 -Recurse + } + If (Test-Path $Objects64) { + Remove-Item $Objects64 -Recurse + } +} #This includes fixes by xsisbest Function FixWhitelistedApps { @@ -560,20 +488,20 @@ $RemoveAllBloatware.Add_Click( { Param([switch]$Debloat) - If (Get-Service -Name dmwappushservice | Where-Object {$_.StartType -eq "Disabled"}) { - Set-Service -Name dmwappushservice -StartupType Automatic + If (Get-Service dmwappushservice | Where-Object {$_.StartType -eq "Disabled"}) { + Set-Service dmwappushservice -StartupType Automatic } - If (Get-Service -Name dmwappushservice | Where-Object {$_.Status -eq "Stopped"}) { - Start-Service -Name dmwappushservice + If (Get-Service dmwappushservice | Where-Object {$_.Status -eq "Stopped"}) { + Start-Service dmwappushservice } } Function CheckInstallService { - If (Get-Service -Name InstallService | Where-Object {$_.Status -eq "Stopped"}) { - Start-Service -Name InstallService - Set-Service -Name InstallService -StartupType Automatic + If (Get-Service InstallService | Where-Object {$_.Status -eq "Stopped"}) { + Start-Service InstallService + Set-Service InstallService -StartupType Automatic } } @@ -581,18 +509,15 @@ $RemoveAllBloatware.Add_Click( { Begin-SysPrep Write-Host "Removing bloatware apps." DebloatAll - DebloatBlacklist Write-Host "Removing leftover bloatware registry keys." Remove-Keys Write-Host "Checking to see if any Whitelisted Apps were removed, and if so re-adding them." FixWhitelistedApps Write-Host "Stopping telemetry, disabling unneccessary scheduled tasks, and preventing bloatware from returning." Protect-Privacy - UnpinStart Write-Host "Unpinning tiles from the Start Menu." - #Write-Host "Stopping Edge from taking over as the default PDF Viewer." - #Stop-EdgePDF - Write-Output "Setting the 'InstallService' Windows service back to 'Started' and the Startup Type 'Automatic'." + UnpinStart + Write-Host "Setting the 'InstallService' Windows service back to 'Started' and the Startup Type 'Automatic'." CheckDMWService CheckInstallService Write-Host "Finished all tasks. `n" @@ -613,23 +538,22 @@ $RemoveBloatNoBlacklist.Add_Click( { $ErrorActionPreference = 'silentlycontinue' param([switch]$SysPrep) - Write-Host -Message ('Starting Sysprep Fixes') + Write-Host "Starting Sysprep Fixes" # Disable Windows Store Automatic Updates - Write-Host -Message "Adding Registry key to Disable Windows Store Automatic Updates" + Write-Host "Adding Registry key to Disable Windows Store Automatic Updates" $registryPath = "HKLM:\SOFTWARE\Policies\Microsoft\WindowsStore" If (!(Test-Path $registryPath)) { - Mkdir $registryPath -ErrorAction SilentlyContinue - New-ItemProperty $registryPath -Name AutoDownload -Value 2 - } - Else { - Set-ItemProperty $registryPath -Name AutoDownload -Value 2 + Mkdir $registryPath + New-ItemProperty $registryPath AutoDownload -Value 2 } + Set-ItemProperty $registryPath AutoDownload -Value 2 + #Stop WindowsStore Installer Service and set to Disabled - Write-Host -Message ('Stopping InstallService') + Write-Host "Stopping InstallService" Stop-Service InstallService - Write-Host -Message ('Setting InstallService Startup to Disabled') - & Set-Service -Name InstallService -StartupType Disabled + Write-Host "Setting InstallService Startup to Disabled" + & Set-Service InstallService -StartupType Disabled } #Creates a PSDrive to be able to access the 'HKCR' tree @@ -644,10 +568,10 @@ $RemoveBloatNoBlacklist.Add_Click( { [regex]$WhitelistedApps = 'Microsoft.ScreenSketch|Microsoft.Paint3D|Microsoft.WindowsCalculator|Microsoft.WindowsStore|Microsoft.Windows.Photos|CanonicalGroupLimited.UbuntuonWindows|` Microsoft.XboxGameCallableUI|Microsoft.XboxGamingOverlay|Microsoft.Xbox.TCUI|Microsoft.XboxGamingOverlay|Microsoft.XboxIdentityProvider|Microsoft.MicrosoftStickyNotes|Microsoft.MSPaint|Microsoft.WindowsCamera|.NET|Framework|` Microsoft.HEIFImageExtension|Microsoft.ScreenSketch|Microsoft.StorePurchaseApp|Microsoft.VP9VideoExtensions|Microsoft.WebMediaExtensions|Microsoft.WebpImageExtension|Microsoft.DesktopAppInstaller|WindSynthBerry|MIDIBerry|Slack' - Get-AppxPackage -AllUsers | Where-Object {$_.Name -NotMatch $WhitelistedApps} | Remove-AppxPackage -ErrorAction SilentlyContinue + Get-AppxPackage -AllUsers | Where-Object {$_.Name -NotMatch $WhitelistedApps} | Remove-AppxPackage # Run this again to avoid error on 1803 or having to reboot. - Get-AppxPackage -AllUsers | Where-Object {$_.Name -NotMatch $WhitelistedApps} | Remove-AppxPackage -ErrorAction SilentlyContinue - Get-AppxProvisionedPackage -Online | Where-Object {$_.PackageName -NotMatch $WhitelistedApps} | Remove-AppxProvisionedPackage -Online -ErrorAction SilentlyContinue + Get-AppxPackage -AllUsers | Where-Object {$_.Name -NotMatch $WhitelistedApps} | Remove-AppxPackage + Get-AppxProvisionedPackage -Online | Where-Object {$_.PackageName -NotMatch $WhitelistedApps} | Remove-AppxProvisionedPackage -Online } Function Remove-Keys { @@ -693,7 +617,7 @@ $RemoveBloatNoBlacklist.Add_Click( { #This writes the output of each key it is removing and also removes the keys listed above. ForEach ($Key in $Keys) { Write-Host "Removing $Key from registry" - Remove-Item $Key -Recurse -ErrorAction SilentlyContinue + Remove-Item $Key -Recurse } } @@ -709,14 +633,14 @@ $RemoveBloatNoBlacklist.Add_Click( { Write-Host "Disabling Windows Feedback Experience program" $Advertising = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AdvertisingInfo' If (Test-Path $Advertising) { - Set-ItemProperty $Advertising -Name Enabled -Value 0 -Verbose + Set-ItemProperty $Advertising Enabled -Value 0 -Verbose } #Stops Cortana from being used as part of your Windows Search Function Write-Host "Stopping Cortana from being used as part of your Windows Search Function" $Search = 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\Windows Search' If (Test-Path $Search) { - Set-ItemProperty $Search -Name AllowCortana -Value 0 -Verbose + Set-ItemProperty $Search AllowCortana -Value 0 -Verbose } #Stops the Windows Feedback Experience from sending anonymous data @@ -725,56 +649,56 @@ $RemoveBloatNoBlacklist.Add_Click( { $Period2 = 'HKCU:\Software\Microsoft\Siuf\Rules' $Period3 = 'HKCU:\Software\Microsoft\Siuf\Rules\PeriodInNanoSeconds' If (!(Test-Path $Period3)) { - mkdir $Period1 -ErrorAction SilentlyContinue - mkdir $Period2 -ErrorAction SilentlyContinue - mkdir $Period3 -ErrorAction SilentlyContinue - New-ItemProperty $Period3 -Name PeriodInNanoSeconds -Value 0 -Verbose -ErrorAction SilentlyContinue + mkdir $Period1 + mkdir $Period2 + mkdir $Period3 + New-ItemProperty $Period3 PeriodInNanoSeconds -Value 0 -Verbose } Write-Host "Adding Registry key to prevent bloatware apps from returning" #Prevents bloatware applications from returning $registryPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\CloudContent" If (!(Test-Path $registryPath)) { - Mkdir $registryPath -ErrorAction SilentlyContinue - New-ItemProperty $registryPath -Name DisableWindowsConsumerFeatures -Value 1 -Verbose -ErrorAction SilentlyContinue + Mkdir $registryPath + New-ItemProperty $registryPath DisableWindowsConsumerFeatures -Value 1 -Verbose } Write-Host "Setting Mixed Reality Portal value to 0 so that you can uninstall it in Settings" $Holo = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Holographic' If (Test-Path $Holo) { - Set-ItemProperty $Holo -Name FirstRunSucceeded -Value 0 -Verbose + Set-ItemProperty $Holo FirstRunSucceeded -Value 0 -Verbose } #Disables live tiles Write-Host "Disabling live tiles" $Live = 'HKCU:\SOFTWARE\Policies\Microsoft\Windows\CurrentVersion\PushNotifications' If (!(Test-Path $Live)) { - mkdir $Live -ErrorAction SilentlyContinue - New-ItemProperty $Live -Name NoTileApplicationNotification -Value 1 -Verbose + mkdir $Live + New-ItemProperty $Live NoTileApplicationNotification -Value 1 -Verbose } #Turns off Data Collection via the AllowTelemtry key by changing it to 0 Write-Host "Turning off Data Collection" $DataCollection = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection' If (Test-Path $DataCollection) { - Set-ItemProperty $DataCollection -Name AllowTelemetry -Value 0 -Verbose + Set-ItemProperty $DataCollection AllowTelemetry -Value 0 -Verbose } #Disables People icon on Taskbar Write-Host "Disabling People icon on Taskbar" $People = 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\People' If (Test-Path $People) { - Set-ItemProperty $People -Name PeopleBand -Value 0 -Verbose + Set-ItemProperty $People PeopleBand -Value 0 -Verbose } #Disables suggestions on start menu Write-Host "Disabling suggestions on the Start Menu" $Suggestions = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager' If (Test-Path $Suggestions) { - Set-ItemProperty $Suggestions -Name SystemPaneSuggestionsEnabled -Value 0 -Verbose + Set-ItemProperty $Suggestions SystemPaneSuggestionsEnabled -Value 0 -Verbose } - Write-Output "Removing CloudStore from registry if it exists" + Write-Host "Removing CloudStore from registry if it exists" $CloudStore = 'HKCUSoftware\Microsoft\Windows\CurrentVersion\CloudStore' If (Test-Path $CloudStore) { Stop-Process Explorer.exe -Force @@ -791,12 +715,12 @@ $RemoveBloatNoBlacklist.Add_Click( { #Disables scheduled tasks that are considered unnecessary Write-Host "Disabling scheduled tasks" - #Get-ScheduledTask -TaskName XblGameSaveTaskLogon | Disable-ScheduledTask -ErrorAction SilentlyContinue - Get-ScheduledTask -TaskName XblGameSaveTask | Disable-ScheduledTask -ErrorAction SilentlyContinue - Get-ScheduledTask -TaskName Consolidator | Disable-ScheduledTask -ErrorAction SilentlyContinue - Get-ScheduledTask -TaskName UsbCeip | Disable-ScheduledTask -ErrorAction SilentlyContinue - Get-ScheduledTask -TaskName DmClient | Disable-ScheduledTask -ErrorAction SilentlyContinue - Get-ScheduledTask -TaskName DmClientOnScenarioDownload | Disable-ScheduledTask -ErrorAction SilentlyContinue + Get-ScheduledTask -TaskName XblGameSaveTaskLogon | Disable-ScheduledTask + Get-ScheduledTask -TaskName XblGameSaveTask | Disable-ScheduledTask + Get-ScheduledTask -TaskName Consolidator | Disable-ScheduledTask + Get-ScheduledTask -TaskName UsbCeip | Disable-ScheduledTask + Get-ScheduledTask -TaskName DmClient | Disable-ScheduledTask + Get-ScheduledTask -TaskName DmClientOnScenarioDownload | Disable-ScheduledTask } Function UnpinStart { @@ -834,20 +758,20 @@ $RemoveBloatNoBlacklist.Add_Click( { Param([switch]$Debloat) - If (Get-Service -Name dmwappushservice | Where-Object {$_.StartType -eq "Disabled"}) { - Set-Service -Name dmwappushservice -StartupType Automatic + If (Get-Service dmwappushservice | Where-Object {$_.StartType -eq "Disabled"}) { + Set-Service dmwappushservice -StartupType Automatic } - If (Get-Service -Name dmwappushservice | Where-Object {$_.Status -eq "Stopped"}) { - Start-Service -Name dmwappushservice + If (Get-Service dmwappushservice | Where-Object {$_.Status -eq "Stopped"}) { + Start-Service dmwappushservice } } Function CheckInstallService { - If (Get-Service -Name InstallService | Where-Object {$_.Status -eq "Stopped"}) { - Start-Service -Name InstallService - Set-Service -Name InstallService -StartupType Automatic + If (Get-Service InstallService | Where-Object {$_.Status -eq "Stopped"}) { + Start-Service InstallService + Set-Service InstallService -StartupType Automatic } } @@ -860,12 +784,12 @@ $RemoveBloatNoBlacklist.Add_Click( { FixWhitelistedApps Write-Host "Stopping telemetry, disabling unneccessary scheduled tasks, and preventing bloatware from returning." Protect-Privacy - UnpinStart Write-Host "Unpinning tiles from the Start Menu." - #Write-Host "Stopping Edge from taking over as the default PDF Viewer." + UnpinStart + Write-Host "Stopping Edge from taking over as the default PDF Viewer." Write-Host "Checking to make sure that the service 'dmwappushservice' has been started." CheckDMWService - Write-Output "Setting the 'InstallService' Windows service back to started and setting the Startup Type to 'Automatic'." + Write-Host "Setting the 'InstallService' Windows service back to started and setting the Startup Type to 'Automatic'." CheckInstallService Write-Host "Finished all tasks. `n" @@ -963,7 +887,18 @@ $RevertChange.Add_Click( { #Enabling the Diagnostics Tracking Service Set-Service "DiagTrack" -StartupType Automatic Start-Service "DiagTrack" - Write-Host "Done reverting changes! `n" + Write-Host "Done reverting changes!" + + # + Write-Output "Restoring 3D Objects from explorer 'My Computer' submenu" + $Objects32 = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{0DB7E03F-FC29-4DC6-9020-FF41B59E513A}" + $Objects64 = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{0DB7E03F-FC29-4DC6-9020-FF41B59E513A}" + If (!(Test-Path $Objects32)) { + New-Item $Objects32 + } + If (!(Test-Path $Objects64)) { + New-Item $Objects64 + } }) $FixWhitelist.Add_Click( { $ErrorActionPreference = 'silentlycontinue' @@ -976,7 +911,7 @@ $FixWhitelist.Add_Click( { Get-AppxPackage -allusers Microsoft.Windows.Photos | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"} } - Write-Host "Whitelisted apps were either fixed or re-added. `n" + Write-Host "Whitelisted apps were either fixed or re-added." }) $DisableCortana.Add_Click( { $ErrorActionPreference = 'silentlycontinue' @@ -997,7 +932,7 @@ $DisableCortana.Add_Click( { New-Item $Cortana3 } Set-ItemProperty $Cortana3 HarvestContacts -Value 0 - Write-Host "Cortana has been disabled. `n" + Write-Host "Cortana has been disabled." }) $StopEdgePDFTakeover.Add_Click( { $ErrorActionPreference = 'silentlycontinue' @@ -1030,7 +965,7 @@ $StopEdgePDFTakeover.Add_Click( { If (Test-Path $Edge) { Set-Item $Edge AppXd4nrz8ff68srnhf9t5a8sbjyar1cr723_ } - Write-Host "Edge should no longer take over as the default .PDF. `n" + Write-Host "Edge should no longer take over as the default .PDF." }) $EnableCortana.Add_Click( { $ErrorActionPreference = 'silentlycontinue' @@ -1051,7 +986,7 @@ $EnableCortana.Add_Click( { New-Item $Cortana3 } Set-ItemProperty $Cortana3 HarvestContacts -Value 1 - Write-Host "Cortana has been enabled! `n" + Write-Host "Cortana has been enabled!" }) $EnableEdgePDFTakeover.Add_Click( { New-PSDrive HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT @@ -1085,7 +1020,7 @@ $EnableEdgePDFTakeover.Add_Click( { If (Test-Path $Edge2) { Set-Item $Edge2 AppXd4nrz8ff68srnhf9t5a8sbjyar1cr723 } - Write-Host "Edge will now be able to be used for .PDF. `n" + Write-Host "Edge will now be able to be used for .PDF." }) $DisableTelemetry.Add_Click( { $ErrorActionPreference = 'silentlycontinue' @@ -1201,12 +1136,12 @@ $DisableTelemetry.Add_Click( { Write-Host "Disabling People icon on Taskbar" $People = 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\People' If (Test-Path $People) { - Set-ItemProperty $People -Name PeopleBand -Value 0 -Verbose + Set-ItemProperty $People -Name PeopleBand -Value 0 } #Disables scheduled tasks that are considered unnecessary Write-Host "Disabling scheduled tasks" - Get-ScheduledTask XblGameSaveTaskLogon | Disable-ScheduledTask + #Get-ScheduledTask XblGameSaveTaskLogon | Disable-ScheduledTask Get-ScheduledTask XblGameSaveTask | Disable-ScheduledTask Get-ScheduledTask Consolidator | Disable-ScheduledTask Get-ScheduledTask UsbCeip | Disable-ScheduledTask @@ -1229,7 +1164,7 @@ $DisableTelemetry.Add_Click( { #Disabling the Diagnostics Tracking Service Stop-Service "DiagTrack" Set-Service "DiagTrack" -StartupType Disabled - Write-Host "Telemetry has been disabled! `n" + Write-Host "Telemetry has been disabled!" }) $RemoveRegkeys.Add_Click( { $ErrorActionPreference = 'silentlycontinue' @@ -1272,7 +1207,7 @@ $RemoveRegkeys.Add_Click( { Write-Host "Removing $Key from registry" Remove-Item $Key -Recurse } - Write-Host "Additional bloatware keys have been removed! `n" + Write-Host "Additional bloatware keys have been removed!" }) $UnpinStartMenuTiles.Add_Click( { #https://superuser.com/questions/1068382/how-to-remove-all-the-tiles-in-the-windows-10-start-menu @@ -1287,45 +1222,37 @@ $UnpinStartMenuTiles.Add_Click( { }) $RemoveOnedrive.Add_Click( { - Write-Output "Checking for pre-existing files and folders located in the OneDrive folders..." - Start-Sleep 1 - If (Get-Item -Path "$env:USERPROFILE\OneDrive\*") { - Write-Output "Files found within the OneDrive folder! Checking to see if a folder named OneDriveBackupFiles exists." + If (Test-Path "$env:USERPROFILE\OneDrive\*") { + Write-Host "Files found within the OneDrive folder! Checking to see if a folder named OneDriveBackupFiles exists." Start-Sleep 1 - If (Get-Item "$env:USERPROFILE\Desktop\OneDriveBackupFiles" -ErrorAction SilentlyContinue) { - Write-Output "A folder named OneDriveBackupFiles already exists on your desktop. All files from your OneDrive location will be moved to that folder." + If (Test-Path "$env:USERPROFILE\Desktop\OneDriveBackupFiles") { + Write-Host "A folder named OneDriveBackupFiles already exists on your desktop. All files from your OneDrive location will be moved to that folder." } else { - If (!(Get-Item "$env:USERPROFILE\Desktop\OneDriveBackupFiles" -ErrorAction SilentlyContinue)) { - Write-Output "A folder named OneDriveBackupFiles will be created and will be located on your desktop. All files from your OneDrive location will be located in that folder." + If (!(Test-Path "$env:USERPROFILE\Desktop\OneDriveBackupFiles")) { + Write-Host "A folder named OneDriveBackupFiles will be created and will be located on your desktop. All files from your OneDrive location will be located in that folder." New-item -Path "$env:USERPROFILE\Desktop" -Name "OneDriveBackupFiles"-ItemType Directory -Force - Write-Output "Successfully created the folder 'OneDriveBackupFiles' on your desktop." + Write-Host "Successfully created the folder 'OneDriveBackupFiles' on your desktop." } } Start-Sleep 1 Move-Item -Path "$env:USERPROFILE\OneDrive\*" -Destination "$env:USERPROFILE\Desktop\OneDriveBackupFiles" -Force - Write-Output "Successfully moved all files/folders from your OneDrive folder to the folder 'OneDriveBackupFiles' on your desktop." + Write-Host "Successfully moved all files/folders from your OneDrive folder to the folder 'OneDriveBackupFiles' on your desktop." Start-Sleep 1 - Write-Output "Proceeding with the removal of OneDrive." + Write-Host "Proceeding with the removal of OneDrive." Start-Sleep 1 } Else { - If (!(Get-Item -Path "$env:USERPROFILE\OneDrive\*")) { - Write-Output "Either the OneDrive folder does not exist or there are no files to be found in the folder. Proceeding with removal of OneDrive." - Start-Sleep 1 - } - + Write-Host "Either the OneDrive folder does not exist or there are no files to be found in the folder. Proceeding with removal of OneDrive." + Start-Sleep 1 Write-Host "Enabling the Group Policy 'Prevent the usage of OneDrive for File Storage'." $OneDriveKey = 'HKLM:Software\Policies\Microsoft\Windows\OneDrive' If (!(Test-Path $OneDriveKey)) { - Mkdir $OneDriveKey - } - - $DisableAllOneDrive = 'HKLM:Software\Policies\Microsoft\Windows\OneDrive' - If (Test-Path $DisableAllOneDrive) { - New-ItemProperty $DisableAllOneDrive -Name OneDrive -Value DisableFileSyncNGSC -Verbose + Mkdir $OneDriveKey + Set-ItemProperty $OneDriveKey -Name OneDrive -Value DisableFileSyncNGSC } + Set-ItemProperty $OneDriveKey -Name OneDrive -Value DisableFileSyncNGSC } Write-Host "Uninstalling OneDrive. Please wait..." @@ -1343,12 +1270,18 @@ $RemoveOnedrive.Add_Click( { Start-Sleep 2 Write-Host "Stopping explorer" Start-Sleep 1 - .\taskkill.exe /F /IM explorer.exe + taskkill.exe /F /IM explorer.exe Start-Sleep 3 Write-Host "Removing leftover files" - Remove-Item "$env:USERPROFILE\OneDrive" -Force -Recurse - Remove-Item "$env:LOCALAPPDATA\Microsoft\OneDrive" -Force -Recurse - Remove-Item "$env:PROGRAMDATA\Microsoft OneDrive" -Force -Recurse + If (Test-Path "$env:USERPROFILE\OneDrive") { + Remove-Item "$env:USERPROFILE\OneDrive" -Force -Recurse + } + If (Test-Path "$env:LOCALAPPDATA\Microsoft\OneDrive") { + Remove-Item "$env:LOCALAPPDATA\Microsoft\OneDrive" -Force -Recurse + } + If (Test-Path "$env:PROGRAMDATA\Microsoft OneDrive") { + Remove-Item "$env:PROGRAMDATA\Microsoft OneDrive" -Force -Recurse + } If (Test-Path "$env:SYSTEMDRIVE\OneDriveTemp") { Remove-Item "$env:SYSTEMDRIVE\OneDriveTemp" -Force -Recurse } @@ -1363,36 +1296,14 @@ $RemoveOnedrive.Add_Click( { Set-ItemProperty $ExplorerReg2 System.IsPinnedToNameSpaceTree -Value 0 Write-Host "Restarting Explorer that was shut down before." Start-Process explorer.exe -NoNewWindow - Write-Host "OneDrive has been successfully uninstalled! `n" - - Write-Host "Enabling the Group Policy 'Prevent the usage of OneDrive for File Storage'." - $OneDriveKey = 'HKLM:Software\Policies\Microsoft\Windows\OneDrive' - If (!(Test-Path $OneDriveKey)) { - Mkdir $OneDriveKey - } - - $DisableAllOneDrive = 'HKLM:Software\Policies\Microsoft\Windows\OneDrive' - If (Test-Path $DisableAllOneDrive) { - New-ItemProperty $DisableAllOneDrive -Name OneDrive -Value DisableFileSyncNGSC -Verbose - } + Write-Host "OneDrive has been successfully uninstalled!" }) $InstallNet35.Add_Click( { Write-Host "Initializing the installation of .NET 3.5..." - Try { - Write-Host "Installing now. Please wait..." - DISM /Online /Enable-Feature /FeatureName:NetFx3 /All - Write-Host ".NET 3.5 has been successfully installed!" - } - Catch { - $_ - } + DISM /Online /Enable-Feature /FeatureName:NetFx3 /All + Write-Host ".NET 3.5 has been successfully installed!" } ) - -#endregion events } - -#endregion GUI } - [void]$Form.ShowDialog() From 2c587f3fb4a2deaa2947dd98a44942eaffa0eb62 Mon Sep 17 00:00:00 2001 From: Damian Date: Mon, 4 Mar 2019 23:19:11 -0500 Subject: [PATCH 2/6] Optimized DebloatAll and slimmed code more added ' -and $_.NonRemovable -eq "False"' to the Get-AppxPackage code lines to help sort through apps that can't get deleted and just get skipped anyways. Onedrive fixes and code reuse from GUI moved over to interactive script code. Removed [CmdletBinding()] and Param() that wasn't being used. Fixed Write-Output to Write-Host Added ' -and $_.NonRemovable -eq "False"' to GUI code as well in the DebloatAll function --- Windows10Debloater.ps1 | 267 +++++++++++++++++--------------------- Windows10DebloaterGUI.ps1 | 14 +- 2 files changed, 125 insertions(+), 156 deletions(-) diff --git a/Windows10Debloater.ps1 b/Windows10Debloater.ps1 index 703fe29..c930c42 100644 --- a/Windows10Debloater.ps1 +++ b/Windows10Debloater.ps1 @@ -28,25 +28,17 @@ Start-Transcript -OutputDirectory "$DebloatFolder" Add-Type -AssemblyName PresentationCore, PresentationFramework Function DebloatAll { - - [CmdletBinding()] - - Param() - #Removes AppxPackages #Credit to /u/GavinEke for a modified version of my whitelist code - [regex]$WhitelistedApps = 'Microsoft.ScreenSketch|Microsoft.Paint3D|Microsoft.WindowsCalculator|Microsoft.WindowsStore|Microsoft.Windows.Photos|CanonicalGroupLimited.UbuntuonWindows|` + $WhitelistedApps = 'Microsoft.ScreenSketch|Microsoft.Paint3D|Microsoft.WindowsCalculator|Microsoft.WindowsStore|Microsoft.Windows.Photos|CanonicalGroupLimited.UbuntuonWindows|` Microsoft.XboxGameCallableUI|Microsoft.XboxGamingOverlay|Microsoft.Xbox.TCUI|Microsoft.XboxGamingOverlay|Microsoft.XboxIdentityProvider|Microsoft.MicrosoftStickyNotes|Microsoft.MSPaint|Microsoft.WindowsCamera|.NET|Framework|` Microsoft.HEIFImageExtension|Microsoft.ScreenSketch|Microsoft.StorePurchaseApp|Microsoft.VP9VideoExtensions|Microsoft.WebMediaExtensions|Microsoft.WebpImageExtension|Microsoft.DesktopAppInstaller|WindSynthBerry|MIDIBerry|Slack' - Get-AppxPackage -AllUsers | Where-Object {$_.Name -NotMatch $WhitelistedApps} | Remove-AppxPackage - Get-AppxPackage | Where-Object {$_.Name -NotMatch $WhitelistedApps} | Remove-AppxPackage - Get-AppxProvisionedPackage -Online | Where-Object {$_.PackageName -NotMatch $WhitelistedApps} | Remove-AppxProvisionedPackage -Online + Get-AppxPackage -AllUsers | Where-Object {$_.Name -NotMatch $WhitelistedApps -and $_.NonRemovable -eq "False"} | Remove-AppxPackage + Get-AppxPackage | Where-Object {$_.Name -NotMatch $WhitelistedApps -and $_.NonRemovable -eq "False"} | Remove-AppxPackage + Get-AppxProvisionedPackage -Online | Where-Object {$_.PackageName -NotMatch $WhitelistedApps -and $_.NonRemovable -eq "False"} | Remove-AppxProvisionedPackage -Online } Function DebloatBlacklist { - [CmdletBinding()] - - Param () $Bloatware = @( @@ -116,18 +108,14 @@ Function DebloatBlacklist { #"*Microsoft.WindowsStore*" ) foreach ($Bloat in $Bloatware) { - Get-AppxPackage -Name $Bloat| Remove-AppxPackage -ErrorAction SilentlyContinue - Get-AppxProvisionedPackage -Online | Where-Object DisplayName -like $Bloat | Remove-AppxProvisionedPackage -Online -ErrorAction SilentlyContinue + Get-AppxPackage -Name $Bloat| Remove-AppxPackage + Get-AppxProvisionedPackage -Online | Where-Object DisplayName -like $Bloat | Remove-AppxProvisionedPackage -Online Write-Output "Trying to remove $Bloat." } } Function Remove-Keys { - [CmdletBinding()] - - Param() - #These are the registry keys that it will delete. $Keys = @( @@ -171,10 +159,6 @@ Function Remove-Keys { } Function Protect-Privacy { - - [CmdletBinding()] - - Param() #Disables Windows Feedback Experience Write-Output "Disabling Windows Feedback Experience program" @@ -288,7 +272,7 @@ Function Protect-Privacy { Write-Output "Disabling People icon on Taskbar" $People = 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\People' If (Test-Path $People) { - Set-ItemProperty $People -Name PeopleBand -Value 0 -Verbose + Set-ItemProperty $People -Name PeopleBand -Value 0 } #Disables scheduled tasks that are considered unnecessary @@ -390,10 +374,6 @@ Function Stop-EdgePDF { } Function Revert-Changes { - - [CmdletBinding()] - - Param() #This function will revert the changes you made when running the Start-Debloat function. @@ -538,10 +518,6 @@ Function Enable-EdgePDF { Function FixWhitelistedApps { - [CmdletBinding()] - - Param() - If (!(Get-AppxPackage -AllUsers | Select Microsoft.Paint3D, Microsoft.WindowsCalculator, Microsoft.WindowsStore, Microsoft.Windows.Photos)) { #Credit to abulgatz for these 4 lines of code @@ -554,88 +530,89 @@ Function FixWhitelistedApps { Function UninstallOneDrive { - Write-Output "Checking for pre-existing files and folders located in the OneDrive folders..." + Write-Host "Checking for pre-existing files and folders located in the OneDrive folders..." Start-Sleep 1 - If (Get-Item -Path "$env:USERPROFILE\OneDrive\*") { - Write-Output "Files found within the OneDrive folder! Checking to see if a folder named OneDriveBackupFiles exists." - Start-Sleep 1 + If (Test-Path "$env:USERPROFILE\OneDrive\*") { + Write-Host "Files found within the OneDrive folder! Checking to see if a folder named OneDriveBackupFiles exists." + Start-Sleep 1 - If (Get-Item "$env:USERPROFILE\Desktop\OneDriveBackupFiles" -ErrorAction SilentlyContinue) { - Write-Output "A folder named OneDriveBackupFiles already exists on your desktop. All files from your OneDrive location will be moved to that folder." - } - else { - If (!(Get-Item "$env:USERPROFILE\Desktop\OneDriveBackupFiles" -ErrorAction SilentlyContinue)) { - Write-Output "A folder named OneDriveBackupFiles will be created and will be located on your desktop. All files from your OneDrive location will be located in that folder." - New-item -Path "$env:USERPROFILE\Desktop" -Name "OneDriveBackupFiles"-ItemType Directory -Force - Write-Output "Successfully created the folder 'OneDriveBackupFiles' on your desktop." + If (Test-Path "$env:USERPROFILE\Desktop\OneDriveBackupFiles") { + Write-Host "A folder named OneDriveBackupFiles already exists on your desktop. All files from your OneDrive location will be moved to that folder." } + else { + If (!(Test-Path "$env:USERPROFILE\Desktop\OneDriveBackupFiles")) { + Write-Host "A folder named OneDriveBackupFiles will be created and will be located on your desktop. All files from your OneDrive location will be located in that folder." + New-item -Path "$env:USERPROFILE\Desktop" -Name "OneDriveBackupFiles"-ItemType Directory -Force + Write-Host "Successfully created the folder 'OneDriveBackupFiles' on your desktop." + } + } + Start-Sleep 1 + Move-Item -Path "$env:USERPROFILE\OneDrive\*" -Destination "$env:USERPROFILE\Desktop\OneDriveBackupFiles" -Force + Write-Host "Successfully moved all files/folders from your OneDrive folder to the folder 'OneDriveBackupFiles' on your desktop." + Start-Sleep 1 + Write-Host "Proceeding with the removal of OneDrive." + Start-Sleep 1 } - Start-Sleep 1 - Move-Item -Path "$env:USERPROFILE\OneDrive\*" -Destination "$env:USERPROFILE\Desktop\OneDriveBackupFiles" -Force - Write-Output "Successfully moved all files/folders from your OneDrive folder to the folder 'OneDriveBackupFiles' on your desktop." - Start-Sleep 1 - Write-Output "Proceeding with the removal of OneDrive." - Start-Sleep 1 - } - Else { - If (!(Get-Item -Path "$env:USERPROFILE\OneDrive\*")) { - Write-Output "Either the OneDrive folder does not exist or there are no files to be found in the folder. Proceeding with removal of OneDrive." + Else { + Write-Host "Either the OneDrive folder does not exist or there are no files to be found in the folder. Proceeding with removal of OneDrive." Start-Sleep 1 + Write-Host "Enabling the Group Policy 'Prevent the usage of OneDrive for File Storage'." + $OneDriveKey = 'HKLM:Software\Policies\Microsoft\Windows\OneDrive' + If (!(Test-Path $OneDriveKey)) { + Mkdir $OneDriveKey + Set-ItemProperty $OneDriveKey -Name OneDrive -Value DisableFileSyncNGSC + } + Set-ItemProperty $OneDriveKey -Name OneDrive -Value DisableFileSyncNGSC } - } - Write-Output "Uninstalling OneDrive" + Write-Host "Uninstalling OneDrive. Please wait..." - New-PSDrive HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT - $onedrive = "$env:SYSTEMROOT\SysWOW64\OneDriveSetup.exe" - $ExplorerReg1 = "HKCR:\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" - $ExplorerReg2 = "HKCR:\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" - Stop-Process -Name "OneDrive*" - Start-Sleep 2 - If (!(Test-Path $onedrive)) { - $onedrive = "$env:SYSTEMROOT\System32\OneDriveSetup.exe" - } - Start-Process $onedrive "/uninstall" -NoNewWindow -Wait - Start-Sleep 2 - Write-Output "Stopping explorer" - Start-Sleep 1 - .\taskkill.exe /F /IM explorer.exe - Start-Sleep 3 - Write-Output "Removing leftover files" - Remove-Item "$env:USERPROFILE\OneDrive" -Force -Recurse - Remove-Item "$env:LOCALAPPDATA\Microsoft\OneDrive" -Force -Recurse - Remove-Item "$env:PROGRAMDATA\Microsoft OneDrive" -Force -Recurse - If (Test-Path "$env:SYSTEMDRIVE\OneDriveTemp") { - Remove-Item "$env:SYSTEMDRIVE\OneDriveTemp" -Force -Recurse - } - Write-Output "Removing OneDrive from windows explorer" - If (!(Test-Path $ExplorerReg1)) { - New-Item $ExplorerReg1 - } - Set-ItemProperty $ExplorerReg1 System.IsPinnedToNameSpaceTree -Value 0 - If (!(Test-Path $ExplorerReg2)) { - New-Item $ExplorerReg2 - } - Set-ItemProperty $ExplorerReg2 System.IsPinnedToNameSpaceTree -Value 0 - Write-Output "Restarting Explorer that was shut down before." - Start-Process explorer.exe -NoNewWindow - - Write-Host "Enabling the Group Policy 'Prevent the usage of OneDrive for File Storage'." - $OneDriveKey = 'HKLM:Software\Policies\Microsoft\Windows\OneDrive' - If (!(Test-Path $OneDriveKey)) { - Mkdir $OneDriveKey + New-PSDrive HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT + $onedrive = "$env:SYSTEMROOT\SysWOW64\OneDriveSetup.exe" + $ExplorerReg1 = "HKCR:\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" + $ExplorerReg2 = "HKCR:\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" + Stop-Process -Name "OneDrive*" + Start-Sleep 2 + If (!(Test-Path $onedrive)) { + $onedrive = "$env:SYSTEMROOT\System32\OneDriveSetup.exe" } - - $DisableAllOneDrive = 'HKLM:Software\Policies\Microsoft\Windows\OneDrive' - If (Test-Path $DisableAllOneDrive) { - New-ItemProperty $DisableAllOneDrive -Name OneDrive -Value DisableFileSyncNGSC -Verbose + Start-Process $onedrive "/uninstall" -NoNewWindow -Wait + Start-Sleep 2 + Write-Host "Stopping explorer" + Start-Sleep 1 + taskkill.exe /F /IM explorer.exe + Start-Sleep 3 + Write-Host "Removing leftover files" + If (Test-Path "$env:USERPROFILE\OneDrive") { + Remove-Item "$env:USERPROFILE\OneDrive" -Force -Recurse + } + If (Test-Path "$env:LOCALAPPDATA\Microsoft\OneDrive") { + Remove-Item "$env:LOCALAPPDATA\Microsoft\OneDrive" -Force -Recurse + } + If (Test-Path "$env:PROGRAMDATA\Microsoft OneDrive") { + Remove-Item "$env:PROGRAMDATA\Microsoft OneDrive" -Force -Recurse + } + If (Test-Path "$env:SYSTEMDRIVE\OneDriveTemp") { + Remove-Item "$env:SYSTEMDRIVE\OneDriveTemp" -Force -Recurse + } + Write-Host "Removing OneDrive from windows explorer" + If (!(Test-Path $ExplorerReg1)) { + New-Item $ExplorerReg1 + } + Set-ItemProperty $ExplorerReg1 System.IsPinnedToNameSpaceTree -Value 0 + If (!(Test-Path $ExplorerReg2)) { + New-Item $ExplorerReg2 } + Set-ItemProperty $ExplorerReg2 System.IsPinnedToNameSpaceTree -Value 0 + Write-Host "Restarting Explorer that was shut down before." + Start-Process explorer.exe -NoNewWindow + Write-Host "OneDrive has been successfully uninstalled!" } Function UnpinStart { #https://superuser.com/questions/1068382/how-to-remove-all-the-tiles-in-the-windows-10-start-menu #Unpins all tiles from the Start Menu - Write-Output "Unpinning all tiles from the start menu" + Write-Host "Unpinning all tiles from the start menu" (New-Object -Com Shell.Application). NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}'). Items() | @@ -646,7 +623,7 @@ Function UnpinStart { Function Remove3dObjects { #Removes 3D Objects from the 'My Computer' submenu in explorer - Write-Output "Removing 3D Objects from explorer 'My Computer' submenu" + Write-Host "Removing 3D Objects from explorer 'My Computer' submenu" $Objects32 = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{0DB7E03F-FC29-4DC6-9020-FF41B59E513A}" $Objects64 = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{0DB7E03F-FC29-4DC6-9020-FF41B59E513A}" If (Test-Path $Objects32) { @@ -659,7 +636,7 @@ Function Remove3dObjects { Function Restore3dObjects { #Restores 3D Objects from the 'My Computer' submenu in explorer - Write-Output "Restoring 3D Objects from explorer 'My Computer' submenu" + Write-Host "Restoring 3D Objects from explorer 'My Computer' submenu" $Objects32 = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{0DB7E03F-FC29-4DC6-9020-FF41B59E513A}" $Objects64 = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{0DB7E03F-FC29-4DC6-9020-FF41B59E513A}" If (!(Test-Path $Objects32)) { @@ -698,72 +675,72 @@ Switch ($Prompt1) { switch ($Prompt2) { Yes { #Creates a "drive" to access the HKCR (HKEY_CLASSES_ROOT) - 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." + Write-Host "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." New-PSDrive HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT Start-Sleep 1 - Write-Output "Uninstalling bloatware, please wait." + Write-Host "Uninstalling bloatware, please wait." DebloatAll - Write-Output "Bloatware removed." + Write-Host "Bloatware removed." Start-Sleep 1 - Write-Output "Removing specific registry keys." + Write-Host "Removing specific registry keys." Remove-Keys - Write-Output "Leftover bloatware registry keys removed." + Write-Host "Leftover bloatware registry keys removed." Start-Sleep 1 - Write-Output "Checking to see if any Whitelisted Apps were removed, and if so re-adding them." + Write-Host "Checking to see if any Whitelisted Apps were removed, and if so re-adding them." Start-Sleep 1 FixWhitelistedApps Start-Sleep 1 - Write-Output "Disabling Cortana from search, disabling feedback to Microsoft, and disabling scheduled tasks that are considered to be telemetry or unnecessary." + Write-Host "Disabling Cortana from search, disabling feedback to Microsoft, and disabling scheduled tasks that are considered to be telemetry or unnecessary." Protect-Privacy Start-Sleep 1 DisableCortana - Write-Output "Cortana disabled and removed from search, feedback to Microsoft has been disabled, and scheduled tasks are disabled." + Write-Host "Cortana disabled and removed from search, feedback to Microsoft has been disabled, and scheduled tasks are disabled." Start-Sleep 1 - Write-Output "Stopping and disabling Diagnostics Tracking Service" + Write-Host "Stopping and disabling Diagnostics Tracking Service" DisableDiagTrack - Write-Output "Diagnostics Tracking Service disabled" + Write-Host "Diagnostics Tracking Service disabled" Start-Sleep 1 - Write-Output "Disabling WAP push service" + Write-Host "Disabling WAP push service" DisableWAPPush Start-Sleep 1 - Write-Output "Re-enabling DMWAppushservice if it was disabled" + Write-Host "Re-enabling DMWAppushservice if it was disabled" CheckDMWService Start-Sleep 1 - Write-Output "Removing 3D Objects from the 'My Computer' submenu in explorer" + Write-Host "Removing 3D Objects from the 'My Computer' submenu in explorer" Remove3dObjects Start-Sleep 1 } No { #Creates a "drive" to access the HKCR (HKEY_CLASSES_ROOT) - 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." + Write-Host "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." New-PSDrive HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT Start-Sleep 1 - Write-Output "Uninstalling bloatware, please wait." + Write-Host "Uninstalling bloatware, please wait." DebloatBlacklist - Write-Output "Bloatware removed." + Write-Host "Bloatware removed." Start-Sleep 1 - Write-Output "Removing specific registry keys." + Write-Host "Removing specific registry keys." Remove-Keys - Write-Output "Leftover bloatware registry keys removed." + Write-Host "Leftover bloatware registry keys removed." Start-Sleep 1 - Write-Output "Checking to see if any Whitelisted Apps were removed, and if so re-adding them." + Write-Host "Checking to see if any Whitelisted Apps were removed, and if so re-adding them." Start-Sleep 1 FixWhitelistedApps Start-Sleep 1 - Write-Output "Disabling Cortana from search, disabling feedback to Microsoft, and disabling scheduled tasks that are considered to be telemetry or unnecessary." + Write-Host "Disabling Cortana from search, disabling feedback to Microsoft, and disabling scheduled tasks that are considered to be telemetry or unnecessary." Protect-Privacy Start-Sleep 1 DisableCortana - Write-Output "Cortana disabled and removed from search, feedback to Microsoft has been disabled, and scheduled tasks are disabled." + Write-Host "Cortana disabled and removed from search, feedback to Microsoft has been disabled, and scheduled tasks are disabled." Start-Sleep 1 - Write-Output "Stopping and disabling Diagnostics Tracking Service" + Write-Host "Stopping and disabling Diagnostics Tracking Service" DisableDiagTrack - Write-Output "Diagnostics Tracking Service disabled" + Write-Host "Diagnostics Tracking Service disabled" Start-Sleep 1 - Write-Output "Disabling WAP push service" + Write-Host "Disabling WAP push service" Start-Sleep 1 DisableWAPPush - Write-Output "Re-enabling DMWAppushservice if it was disabled" + Write-Host "Re-enabling DMWAppushservice if it was disabled" CheckDMWService Start-Sleep 1 } @@ -773,10 +750,10 @@ Switch ($Prompt1) { Switch ($Prompt3) { Yes { Stop-EdgePDF - Write-Output "Edge will no longer take over as the default PDF viewer." + Write-Host "Edge will no longer take over as the default PDF viewer." } No { - Write-Output "You chose not to stop Edge from taking over as the default PDF viewer." + Write-Host "You chose not to stop Edge from taking over as the default PDF viewer." } } #Prompt asking to delete OneDrive @@ -784,10 +761,10 @@ Switch ($Prompt1) { Switch ($Prompt4) { Yes { UninstallOneDrive - Write-Output "OneDrive is now removed from the computer." + Write-Host "OneDrive is now removed from the computer." } No { - Write-Output "You have chosen to skip removing OneDrive from your machine." + Write-Host "You have chosen to skip removing OneDrive from your machine." } } #Prompt asking if you'd like to unpin all start items @@ -795,20 +772,20 @@ Switch ($Prompt1) { Switch ($Prompt5) { Yes { UnpinStart - Write-Output "Start Apps unpined." + Write-Host "Start Apps unpined." } No { - Write-Output "You have chosen to skip removing OneDrive from your machine." + Write-Host "You have chosen to skip removing OneDrive from your machine." } } $Prompt6 = [Windows.MessageBox]::Show($InstallNET, "Install .Net", $Button, $Warn) Switch ($Prompt6) { Yes { - Write-Output "Initializing the installation of .NET 3.5..." + Write-Host "Initializing the installation of .NET 3.5..." Try { DISM /Online /Enable-Feature /FeatureName:NetFx3 /All - Write-Output ".NET 3.5 has been successfully installed!" } + Write-Host ".NET 3.5 has been successfully installed!" } Catch { $_ } @@ -818,28 +795,28 @@ Switch ($Prompt1) { $Prompt7 = [Windows.MessageBox]::Show($Reboot, "Reboot", $Button, $Warn) Switch ($Prompt7) { Yes { - Write-Output "Unloading the HKCR drive..." + Write-Host "Unloading the HKCR drive..." Remove-PSDrive HKCR Start-Sleep 1 Stop-Transcript - Write-Output "Initiating reboot." + Write-Host "Initiating reboot." Start-Sleep 2 Restart-Computer } No { - Write-Output "Unloading the HKCR drive..." + Write-Host "Unloading the HKCR drive..." Remove-PSDrive HKCR Start-Sleep 1 Stop-Transcript - Write-Output "Script has finished. Exiting." + Write-Host "Script has finished. Exiting." Start-Sleep 2 Exit } } } No { - Write-Output "Reverting changes..." - 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." + Write-Host "Reverting changes..." + Write-Host "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." New-PSDrive HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT Revert-Changes #Prompt asking to revert edge changes as well @@ -847,29 +824,29 @@ Switch ($Prompt1) { Switch ($Prompt6) { Yes { Enable-EdgePDF - Write-Output "Edge will no longer be disabled from being used as the default Edge PDF viewer." + Write-Host "Edge will no longer be disabled from being used as the default Edge PDF viewer." } No { - Write-Output "You have chosen to keep the setting that disallows Edge to be the default PDF viewer." + Write-Host "You have chosen to keep the setting that disallows Edge to be the default PDF viewer." } } #Prompt asking if you'd like to reboot your machine $Prompt7 = [Windows.MessageBox]::Show($Reboot, "Reboot", $Button, $Warn) Switch ($Prompt7) { Yes { - Write-Output "Unloading the HKCR drive..." + Write-Host "Unloading the HKCR drive..." Remove-PSDrive HKCR Start-Sleep 1 - Write-Output "Initiating reboot." + Write-Host "Initiating reboot." Stop-Transcript Start-Sleep 2 Restart-Computer } No { - Write-Output "Unloading the HKCR drive..." + Write-Host "Unloading the HKCR drive..." Remove-PSDrive HKCR Start-Sleep 1 - Write-Output "Script has finished. Exiting." + Write-Host "Script has finished. Exiting." Stop-Transcript Start-Sleep 2 Exit diff --git a/Windows10DebloaterGUI.ps1 b/Windows10DebloaterGUI.ps1 index e7795a1..0508274 100644 --- a/Windows10DebloaterGUI.ps1 +++ b/Windows10DebloaterGUI.ps1 @@ -158,9 +158,6 @@ Start-Transcript -OutputDirectory "$DebloatFolder" $RemoveBlacklist.Add_Click( { $ErrorActionPreference = 'silentlycontinue' Function DebloatBlacklist { - [CmdletBinding()] - - Param () $Bloatware = @( @@ -246,7 +243,6 @@ $RemoveAllBloatware.Add_Click( { #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. Function Begin-SysPrep { - $ErrorActionPreference = 'silentlycontinue' Write-Host "Starting Sysprep Fixes" @@ -281,18 +277,14 @@ $RemoveAllBloatware.Add_Click( { Function DebloatAll { - [CmdletBinding()] - - Param() - #Removes AppxPackages #Credit to /u/GavinEke for a modified version of my whitelist code [regex]$WhitelistedApps = 'Microsoft.ScreenSketch|Microsoft.Paint3D|Microsoft.WindowsCalculator|Microsoft.WindowsStore|Microsoft.Windows.Photos|CanonicalGroupLimited.UbuntuonWindows|` Microsoft.XboxGameCallableUI|Microsoft.XboxGamingOverlay|Microsoft.Xbox.TCUI|Microsoft.XboxGamingOverlay|Microsoft.XboxIdentityProvider|Microsoft.MicrosoftStickyNotes|Microsoft.MSPaint|Microsoft.WindowsCamera|.NET|Framework|` Microsoft.HEIFImageExtension|Microsoft.ScreenSketch|Microsoft.StorePurchaseApp|Microsoft.VP9VideoExtensions|Microsoft.WebMediaExtensions|Microsoft.WebpImageExtension|Microsoft.DesktopAppInstaller|WindSynthBerry|MIDIBerry|Slack' - Get-AppxPackage -AllUsers | Where-Object {$_.Name -NotMatch $WhitelistedApps} | Remove-AppxPackage - Get-AppxPackage | Where-Object {$_.Name -NotMatch $WhitelistedApps} | Remove-AppxPackage - Get-AppxProvisionedPackage -Online | Where-Object {$_.PackageName -NotMatch $WhitelistedApps} | Remove-AppxProvisionedPackage -Online + Get-AppxPackage -AllUsers | Where-Object {$_.Name -NotMatch $WhitelistedApps -and $_.NonRemovable -eq "False"} | Remove-AppxPackage + Get-AppxPackage | Where-Object {$_.Name -NotMatch $WhitelistedApps -and $_.NonRemovable -eq "False"} | Remove-AppxPackage + Get-AppxProvisionedPackage -Online | Where-Object {$_.PackageName -NotMatch $WhitelistedApps -and $_.NonRemovable -eq "False"} | Remove-AppxProvisionedPackage -Online } #Creates a PSDrive to be able to access the 'HKCR' tree From 83fd597a00e52fcdb938362895a5600ede41c794 Mon Sep 17 00:00:00 2001 From: Damian Date: Tue, 5 Mar 2019 01:07:40 -0500 Subject: [PATCH 3/6] Added Dark Mode button(s) to the GUI Also added a small countdown to the admin check --- Windows10Debloater.ps1 | 10 +++++++-- Windows10DebloaterGUI.ps1 | 43 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/Windows10Debloater.ps1 b/Windows10Debloater.ps1 index c930c42..27afa2b 100644 --- a/Windows10Debloater.ps1 +++ b/Windows10Debloater.ps1 @@ -4,7 +4,13 @@ #This will self elevate the script so with a UAC prompt since this script needs to be run as an Administrator in order to function properly. If (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]'Administrator')) { Write-Host "You didn't run this script as an Administrator. This script will self elevate to run as an Administrator and continue." - Start-Sleep 2 + Start-Sleep 1 + Write-Host " 3" + Start-Sleep 1 + Write-Host " 2" + Start-Sleep 1 + Write-Host " 1" + Start-Sleep 1 Start-Process powershell.exe -ArgumentList ("-NoProfile -ExecutionPolicy Bypass -File `"{0}`"" -f $PSCommandPath) -Verb RunAs Exit } @@ -17,7 +23,7 @@ If (Test-Path $DebloatFolder) { Write-Output "$DebloatFolder exists. Skipping." } Else { - Write-Output "The folder "$DebloatFolder" doesn't exist. This folder will be used for storing logs created after the script runs. Creating now." + Write-Output "The folder '$DebloatFolder' doesn't exist. This folder will be used for storing logs created after the script runs. Creating now." Start-Sleep 1 New-Item -Path "$DebloatFolder" -ItemType Directory Write-Output "The folder $DebloatFolder was successfully created." diff --git a/Windows10DebloaterGUI.ps1 b/Windows10DebloaterGUI.ps1 index 0508274..f6ee456 100644 --- a/Windows10DebloaterGUI.ps1 +++ b/Windows10DebloaterGUI.ps1 @@ -1,7 +1,13 @@ #This will self elevate the script so with a UAC prompt since this script needs to be run as an Administrator in order to function properly. If (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]'Administrator')) { Write-Host "You didn't run this script as an Administrator. This script will self elevate to run as an Administrator and continue." - Start-Sleep 2 + Start-Sleep 1 + Write-Host " 3" + Start-Sleep 1 + Write-Host " 2" + Start-Sleep 1 + Write-Host " 1" + Start-Sleep 1 Start-Process powershell.exe -ArgumentList ("-NoProfile -ExecutionPolicy Bypass -File `"{0}`"" -f $PSCommandPath) -Verb RunAs Exit } @@ -138,8 +144,23 @@ $InstallNet35.height = 39 $InstallNet35.location = New-Object System.Drawing.Point(9, 387) $InstallNet35.Font = 'Microsoft Sans Serif,10' +$EnableDarkMode = New-Object system.Windows.Forms.Button +$EnableDarkMode.text = "Enable Dark Mode" +$EnableDarkMode.width = 152 +$EnableDarkMode.height = 39 +$EnableDarkMode.location = New-Object System.Drawing.Point(9, 435) +$EnableDarkMode.Font = 'Microsoft Sans Serif,10' + +$DisableDarkMode = New-Object system.Windows.Forms.Button +$DisableDarkMode.text = "Disable Dark Mode" +$DisableDarkMode.width = 152 +$DisableDarkMode.height = 39 +$DisableDarkMode.location = New-Object System.Drawing.Point(169, 435) +$DisableDarkMode.Font = 'Microsoft Sans Serif,10' + + -$Form.controls.AddRange(@($Debloat, $RemoveAllBloatware, $RemoveBlacklist, $Label1, $RevertChange, $Label2, $DisableCortana, $EnableCortana, $StopEdgePDFTakeover, $EnableEdgePDFTakeover, $DisableTelemetry, $RemoveRegkeys, $UnpinStartMenuTiles, $RemoveOnedrive, $FixWhitelist, $RemoveBloatNoBlacklist, $InstallNet35)) +$Form.controls.AddRange(@($Debloat, $RemoveAllBloatware, $RemoveBlacklist, $Label1, $RevertChange, $Label2, $DisableCortana, $EnableCortana, $StopEdgePDFTakeover, $EnableEdgePDFTakeover, $DisableTelemetry, $RemoveRegkeys, $UnpinStartMenuTiles, $RemoveOnedrive, $FixWhitelist, $RemoveBloatNoBlacklist, $InstallNet35, $EnableDarkMode, $DisableDarkMode)) $DebloatFolder = "C:\Temp\Windows10Debloater" If (Test-Path $DebloatFolder) { @@ -1298,4 +1319,22 @@ $InstallNet35.Add_Click( { Write-Host ".NET 3.5 has been successfully installed!" } ) +$EnableDarkMode.Add_Click( { + Write-Host "Enabling Dark Mode" + $Theme = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize" + Set-ItemProperty $Theme AppsUseLightTheme -Value 0 + Start-Sleep 1 + Write-Host "Enabled" +} +) + +$DisableDarkMode.Add_Click( { + Write-Host "Disabling Dark Mode" + $Theme = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize" + Set-ItemProperty $Theme AppsUseLightTheme -Value 1 + Start-Sleep 1 + Write-Host "Disabled" +} +) + [void]$Form.ShowDialog() From f269dbbee37afc2398cc0780e9b86ba24e9bef74 Mon Sep 17 00:00:00 2001 From: Damian Date: Tue, 5 Mar 2019 22:19:03 -0500 Subject: [PATCH 4/6] Fixed Optimization to skip NonRemovable apps that were always attempted NonRemovable apps were still getting attempted in the debloat all functions that were always throwing errors that were just hanging on initalizing floating above the powershell window running. Fixed Prompt position after the .NET prompt that wouldn't show the Do you want to power down Prompt Fixed the Write-Host saying you didn't want to remove one drive after selecting 'no' to not unpin tiles. --- Windows10Debloater.ps1 | 39 +++++++++++++++++++++++---------------- Windows10DebloaterGUI.ps1 | 17 +++++++++++------ 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/Windows10Debloater.ps1 b/Windows10Debloater.ps1 index 27afa2b..d849d0c 100644 --- a/Windows10Debloater.ps1 +++ b/Windows10Debloater.ps1 @@ -39,9 +39,15 @@ Function DebloatAll { $WhitelistedApps = 'Microsoft.ScreenSketch|Microsoft.Paint3D|Microsoft.WindowsCalculator|Microsoft.WindowsStore|Microsoft.Windows.Photos|CanonicalGroupLimited.UbuntuonWindows|` Microsoft.XboxGameCallableUI|Microsoft.XboxGamingOverlay|Microsoft.Xbox.TCUI|Microsoft.XboxGamingOverlay|Microsoft.XboxIdentityProvider|Microsoft.MicrosoftStickyNotes|Microsoft.MSPaint|Microsoft.WindowsCamera|.NET|Framework|` Microsoft.HEIFImageExtension|Microsoft.ScreenSketch|Microsoft.StorePurchaseApp|Microsoft.VP9VideoExtensions|Microsoft.WebMediaExtensions|Microsoft.WebpImageExtension|Microsoft.DesktopAppInstaller|WindSynthBerry|MIDIBerry|Slack' - Get-AppxPackage -AllUsers | Where-Object {$_.Name -NotMatch $WhitelistedApps -and $_.NonRemovable -eq "False"} | Remove-AppxPackage - Get-AppxPackage | Where-Object {$_.Name -NotMatch $WhitelistedApps -and $_.NonRemovable -eq "False"} | Remove-AppxPackage - Get-AppxProvisionedPackage -Online | Where-Object {$_.PackageName -NotMatch $WhitelistedApps -and $_.NonRemovable -eq "False"} | Remove-AppxProvisionedPackage -Online + #NonRemovable Apps that where getting attempted and the system would reject the uninstall, speeds up debloat and prevents 'initalizing' overlay when removing apps + $NonRemovable = '1527c705-839a-4832-9118-54d4Bd6a0c89|c5e2524a-ea46-4f67-841f-6a9465d9d515|E2A4F912-2574-4A75-9BB0-0D023378592B|F46D4000-FD22-4DB4-AC8E-4E1DDDE828FE|InputApp|Microsoft.AAD.BrokerPlugin|Microsoft.AccountsControl|` + Microsoft.BioEnrollment|Microsoft.CredDialogHost|Microsoft.ECApp|Microsoft.LockApp|Microsoft.MicrosoftEdgeDevToolsClient|Microsoft.MicrosoftEdge|Microsoft.PPIProjection|Microsoft.Win32WebViewHost|Microsoft.Windows.Apprep.ChxApp|` + Microsoft.Windows.AssignedAccessLockApp|Microsoft.Windows.CapturePicker|Microsoft.Windows.CloudExperienceHost|Microsoft.Windows.ContentDeliveryManager|Microsoft.Windows.Cortana|Microsoft.Windows.NarratorQuickStart|` + Microsoft.Windows.ParentalControls|Microsoft.Windows.PeopleExperienceHost|Microsoft.Windows.PinningConfirmationDialog|Microsoft.Windows.SecHealthUI|Microsoft.Windows.SecureAssessmentBrowser|Microsoft.Windows.ShellExperienceHost|` + Microsoft.Windows.XGpuEjectDialog|Microsoft.XboxGameCallableUI|Windows.CBSPreview|windows.immersivecontrolpanel|Windows.PrintDialog|Microsoft.VCLibs.140.00|Microsoft.Services.Store.Engagement|Microsoft.UI.Xaml.2.0' + Get-AppxPackage -AllUsers | Where {$_.Name -NotMatch $WhitelistedApps -and $_.Name -NotMatch $NonRemovable} | Remove-AppxPackage + Get-AppxPackage | Where {$_.Name -NotMatch $WhitelistedApps -and $_.Name -NotMatch $NonRemovable} | Remove-AppxPackage + Get-AppxProvisionedPackage -Online | Where {$_.Name -NotMatch $WhitelistedApps -and $_.Name -NotMatch $NonRemovable} | Remove-AppxProvisionedPackage -Online } Function DebloatBlacklist { @@ -676,7 +682,7 @@ $Prompt1 = [Windows.MessageBox]::Show($Ask, "Debloat or Revert", $Button, $Error Switch ($Prompt1) { #This will debloat Windows 10 Yes { - + #Everything is specific prompt $Prompt2 = [Windows.MessageBox]::Show($EverythingorSpecific, "Everything or Specific", $Button, $Warn) switch ($Prompt2) { Yes { @@ -751,7 +757,7 @@ Switch ($Prompt1) { Start-Sleep 1 } } - + #Disabling EdgePDF prompt $Prompt3 = [Windows.MessageBox]::Show($EdgePdf, "Edge PDF", $Button, $Warn) Switch ($Prompt3) { Yes { @@ -773,7 +779,7 @@ Switch ($Prompt1) { Write-Host "You have chosen to skip removing OneDrive from your machine." } } - #Prompt asking if you'd like to unpin all start items + #Prompt asking if you'd like to unpin all start items $Prompt5 = [Windows.MessageBox]::Show($Unpin, "Unpin", $Button, $ErrorIco) Switch ($Prompt5) { Yes { @@ -781,31 +787,31 @@ Switch ($Prompt1) { Write-Host "Start Apps unpined." } No { - Write-Host "You have chosen to skip removing OneDrive from your machine." + Write-Host "Apps will remain pinned to the start menu." } } + #Prompt asking if you want to install .NET $Prompt6 = [Windows.MessageBox]::Show($InstallNET, "Install .Net", $Button, $Warn) Switch ($Prompt6) { Yes { Write-Host "Initializing the installation of .NET 3.5..." - Try { DISM /Online /Enable-Feature /FeatureName:NetFx3 /All - Write-Host ".NET 3.5 has been successfully installed!" } - Catch { - $_ + Write-Host ".NET 3.5 has been successfully installed!" } + No { + Write-Host "Skipping .NET install." + } } - } #Prompt asking if you'd like to reboot your machine - $Prompt7 = [Windows.MessageBox]::Show($Reboot, "Reboot", $Button, $Warn) + $Prompt7 = [Windows.MessageBox]::Show($Reboot, "Reboot", $Button, $Warn) Switch ($Prompt7) { Yes { Write-Host "Unloading the HKCR drive..." Remove-PSDrive HKCR Start-Sleep 1 - Stop-Transcript Write-Host "Initiating reboot." + Stop-Transcript Start-Sleep 2 Restart-Computer } @@ -813,13 +819,15 @@ Switch ($Prompt1) { Write-Host "Unloading the HKCR drive..." Remove-PSDrive HKCR Start-Sleep 1 - Stop-Transcript Write-Host "Script has finished. Exiting." + Stop-Transcript Start-Sleep 2 Exit } } } +} + No { Write-Host "Reverting changes..." Write-Host "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." @@ -859,4 +867,3 @@ Switch ($Prompt1) { } } } -} diff --git a/Windows10DebloaterGUI.ps1 b/Windows10DebloaterGUI.ps1 index f6ee456..1bbac9f 100644 --- a/Windows10DebloaterGUI.ps1 +++ b/Windows10DebloaterGUI.ps1 @@ -297,16 +297,21 @@ $RemoveAllBloatware.Add_Click( { } Function DebloatAll { - #Removes AppxPackages #Credit to /u/GavinEke for a modified version of my whitelist code - [regex]$WhitelistedApps = 'Microsoft.ScreenSketch|Microsoft.Paint3D|Microsoft.WindowsCalculator|Microsoft.WindowsStore|Microsoft.Windows.Photos|CanonicalGroupLimited.UbuntuonWindows|` + $WhitelistedApps = 'Microsoft.ScreenSketch|Microsoft.Paint3D|Microsoft.WindowsCalculator|Microsoft.WindowsStore|Microsoft.Windows.Photos|CanonicalGroupLimited.UbuntuonWindows|` Microsoft.XboxGameCallableUI|Microsoft.XboxGamingOverlay|Microsoft.Xbox.TCUI|Microsoft.XboxGamingOverlay|Microsoft.XboxIdentityProvider|Microsoft.MicrosoftStickyNotes|Microsoft.MSPaint|Microsoft.WindowsCamera|.NET|Framework|` Microsoft.HEIFImageExtension|Microsoft.ScreenSketch|Microsoft.StorePurchaseApp|Microsoft.VP9VideoExtensions|Microsoft.WebMediaExtensions|Microsoft.WebpImageExtension|Microsoft.DesktopAppInstaller|WindSynthBerry|MIDIBerry|Slack' - Get-AppxPackage -AllUsers | Where-Object {$_.Name -NotMatch $WhitelistedApps -and $_.NonRemovable -eq "False"} | Remove-AppxPackage - Get-AppxPackage | Where-Object {$_.Name -NotMatch $WhitelistedApps -and $_.NonRemovable -eq "False"} | Remove-AppxPackage - Get-AppxProvisionedPackage -Online | Where-Object {$_.PackageName -NotMatch $WhitelistedApps -and $_.NonRemovable -eq "False"} | Remove-AppxProvisionedPackage -Online - } + #NonRemovable Apps that where getting attempted and the system would reject the uninstall, speeds up debloat and prevents 'initalizing' overlay when removing apps + $NonRemovable = '1527c705-839a-4832-9118-54d4Bd6a0c89|c5e2524a-ea46-4f67-841f-6a9465d9d515|E2A4F912-2574-4A75-9BB0-0D023378592B|F46D4000-FD22-4DB4-AC8E-4E1DDDE828FE|InputApp|Microsoft.AAD.BrokerPlugin|Microsoft.AccountsControl|` + Microsoft.BioEnrollment|Microsoft.CredDialogHost|Microsoft.ECApp|Microsoft.LockApp|Microsoft.MicrosoftEdgeDevToolsClient|Microsoft.MicrosoftEdge|Microsoft.PPIProjection|Microsoft.Win32WebViewHost|Microsoft.Windows.Apprep.ChxApp|` + Microsoft.Windows.AssignedAccessLockApp|Microsoft.Windows.CapturePicker|Microsoft.Windows.CloudExperienceHost|Microsoft.Windows.ContentDeliveryManager|Microsoft.Windows.Cortana|Microsoft.Windows.NarratorQuickStart|` + Microsoft.Windows.ParentalControls|Microsoft.Windows.PeopleExperienceHost|Microsoft.Windows.PinningConfirmationDialog|Microsoft.Windows.SecHealthUI|Microsoft.Windows.SecureAssessmentBrowser|Microsoft.Windows.ShellExperienceHost|` + Microsoft.Windows.XGpuEjectDialog|Microsoft.XboxGameCallableUI|Windows.CBSPreview|windows.immersivecontrolpanel|Windows.PrintDialog|Microsoft.VCLibs.140.00|Microsoft.Services.Store.Engagement|Microsoft.UI.Xaml.2.0' + Get-AppxPackage -AllUsers | Where {$_.Name -NotMatch $WhitelistedApps -and $_.Name -NotMatch $NonRemovable} | Remove-AppxPackage + Get-AppxPackage | Where {$_.Name -NotMatch $WhitelistedApps -and $_.Name -NotMatch $NonRemovable} | Remove-AppxPackage + Get-AppxProvisionedPackage -Online | Where {$_.Name -NotMatch $WhitelistedApps -and $_.Name -NotMatch $NonRemovable} | Remove-AppxProvisionedPackage -Online +} #Creates a PSDrive to be able to access the 'HKCR' tree New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT From a7d477333c0bbd70a183aa6b68dd7940fea8fc70 Mon Sep 17 00:00:00 2001 From: Damian Date: Wed, 13 Mar 2019 09:50:05 -0400 Subject: [PATCH 5/6] Update README.md Updated the readme --- README.md | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 910c524..4647e7e 100644 --- a/README.md +++ b/README.md @@ -10,12 +10,10 @@ First Method: 1) Download the .zip file on the main page of the github and extract the .zip file to your desired location 2) Once extracted, open PowerShell (or PowerShell ISE) as an Administrator 3) Enable PowerShell execution -Set-ExecutionPolicy Unrestricted -4) Ubnlock all powershell script -ls -Recurse *.ps1 | Unblock-File -5) On the propmt, change to the directory where you extracted the files: +Set-ExecutionPolicy Unrestricted -Force +4) On the propmt, change to the directory where you extracted the files: e.g. - cd c:\temp -6) Next, to run either script, enter in the following: +5) Next, to run either script, enter in the following: e.g. - .\Windows10DebloaterGUI.ps1 @@ -23,16 +21,9 @@ Second Method: 1) Download the .zip file on the main page of the github and extract the .zip file to your desired location 2) Right click the PowerShell file that you'd like to run and click on "Run With PowerShell" -3) This will allow the script to run without having to do the above steps +3) This will allow the script to run without having to do the above steps but Powershell will ask if you're sure you want to run this script. - -Third Method: - -This method has an issue because my script will launch a PowerShell session as an Administrator if you didn't do so, and if you didn't then this method won't work properly unless you remove the code at the very top that does this. - -1) Download the .zip file on the main page of the github and extract the .zip file to your desired location -2) Open the files and copy and paste the source code into either PowerShell.exe or PowerShell ISE. -3) Click "RUN" (or F5) and the script will run +Remember this script NEEDS to be run as admin in order to function properly. # How To Run the Windows10SysPrepDebloater.ps1 file From 4e1618cb4f55fc6f92d88397011c70907882fbb2 Mon Sep 17 00:00:00 2001 From: Damian Date: Wed, 13 Mar 2019 10:07:45 -0400 Subject: [PATCH 6/6] Update Windows10DebloaterGUI.ps1 Removed DebloatNoBlacklist since it was the exact same as DebloatAll --- Windows10DebloaterGUI.ps1 | 278 -------------------------------------- 1 file changed, 278 deletions(-) diff --git a/Windows10DebloaterGUI.ps1 b/Windows10DebloaterGUI.ps1 index 1bbac9f..8793b32 100644 --- a/Windows10DebloaterGUI.ps1 +++ b/Windows10DebloaterGUI.ps1 @@ -130,13 +130,6 @@ $FixWhitelist.height = 37 $FixWhitelist.location = New-Object System.Drawing.Point(254, 74) $FixWhitelist.Font = 'Microsoft Sans Serif,10' -$RemoveBloatNoBlacklist = New-Object system.Windows.Forms.Button -$RemoveBloatNoBlacklist.text = "Remove Bloatware Without Blacklist" -$RemoveBloatNoBlacklist.width = 223 -$RemoveBloatNoBlacklist.height = 39 -$RemoveBloatNoBlacklist.location = New-Object System.Drawing.Point(9, 123) -$RemoveBloatNoBlacklist.Font = 'Microsoft Sans Serif,10' - $InstallNet35 = New-Object system.Windows.Forms.Button $InstallNet35.text = "Install .NET v3.5" $InstallNet35.width = 152 @@ -541,277 +534,6 @@ $RemoveAllBloatware.Add_Click( { Write-Host "Finished all tasks. `n" } ) -$RemoveBloatNoBlacklist.Add_Click( { - $ErrorActionPreference = 'silentlycontinue' - #This function finds any AppX/AppXProvisioned package and uninstalls it, except for Freshpaint, Windows Calculator, Windows Store, and Windows Photos. - #Also, to note - This does NOT remove essential system services/software/etc such as .NET framework installations, Cortana, Edge, etc. - - #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. - - param ( - [switch]$Debloat, [switch]$SysPrep - ) - - Function Begin-SysPrep { - $ErrorActionPreference = 'silentlycontinue' - - param([switch]$SysPrep) - Write-Host "Starting Sysprep Fixes" - - # Disable Windows Store Automatic Updates - Write-Host "Adding Registry key to Disable Windows Store Automatic Updates" - $registryPath = "HKLM:\SOFTWARE\Policies\Microsoft\WindowsStore" - If (!(Test-Path $registryPath)) { - Mkdir $registryPath - New-ItemProperty $registryPath AutoDownload -Value 2 - } - Set-ItemProperty $registryPath AutoDownload -Value 2 - - #Stop WindowsStore Installer Service and set to Disabled - Write-Host "Stopping InstallService" - Stop-Service InstallService - Write-Host "Setting InstallService Startup to Disabled" - & Set-Service InstallService -StartupType Disabled - } - - #Creates a PSDrive to be able to access the 'HKCR' tree - New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT - Function Start-Debloat { - $ErrorActionPreference = 'silentlycontinue' - - param([switch]$Debloat) - - #Removes AppxPackages - #Credit to Reddit user /u/GavinEke for a modified version of my whitelist code - [regex]$WhitelistedApps = 'Microsoft.ScreenSketch|Microsoft.Paint3D|Microsoft.WindowsCalculator|Microsoft.WindowsStore|Microsoft.Windows.Photos|CanonicalGroupLimited.UbuntuonWindows|` - Microsoft.XboxGameCallableUI|Microsoft.XboxGamingOverlay|Microsoft.Xbox.TCUI|Microsoft.XboxGamingOverlay|Microsoft.XboxIdentityProvider|Microsoft.MicrosoftStickyNotes|Microsoft.MSPaint|Microsoft.WindowsCamera|.NET|Framework|` - Microsoft.HEIFImageExtension|Microsoft.ScreenSketch|Microsoft.StorePurchaseApp|Microsoft.VP9VideoExtensions|Microsoft.WebMediaExtensions|Microsoft.WebpImageExtension|Microsoft.DesktopAppInstaller|WindSynthBerry|MIDIBerry|Slack' - Get-AppxPackage -AllUsers | Where-Object {$_.Name -NotMatch $WhitelistedApps} | Remove-AppxPackage - # Run this again to avoid error on 1803 or having to reboot. - Get-AppxPackage -AllUsers | Where-Object {$_.Name -NotMatch $WhitelistedApps} | Remove-AppxPackage - Get-AppxProvisionedPackage -Online | Where-Object {$_.PackageName -NotMatch $WhitelistedApps} | Remove-AppxProvisionedPackage -Online - } - - Function Remove-Keys { - $ErrorActionPreference = 'silentlycontinue' - - Param([switch]$Debloat) - - #These are the registry keys that it will delete. - - $Keys = @( - - #Remove Background Tasks - "HKCR:\Extensions\ContractId\Windows.BackgroundTasks\PackageId\46928bounde.EclipseManager_2.2.4.51_neutral__a5h4egax66k6y" - "HKCR:\Extensions\ContractId\Windows.BackgroundTasks\PackageId\ActiproSoftwareLLC.562882FEEB491_2.6.18.18_neutral__24pqs290vpjk0" - "HKCR:\Extensions\ContractId\Windows.BackgroundTasks\PackageId\Microsoft.MicrosoftOfficeHub_17.7909.7600.0_x64__8wekyb3d8bbwe" - "HKCR:\Extensions\ContractId\Windows.BackgroundTasks\PackageId\Microsoft.PPIProjection_10.0.15063.0_neutral_neutral_cw5n1h2txyewy" - "HKCR:\Extensions\ContractId\Windows.BackgroundTasks\PackageId\Microsoft.XboxGameCallableUI_1000.15063.0.0_neutral_neutral_cw5n1h2txyewy" - "HKCR:\Extensions\ContractId\Windows.BackgroundTasks\PackageId\Microsoft.XboxGameCallableUI_1000.16299.15.0_neutral_neutral_cw5n1h2txyewy" - - #Windows File - "HKCR:\Extensions\ContractId\Windows.File\PackageId\ActiproSoftwareLLC.562882FEEB491_2.6.18.18_neutral__24pqs290vpjk0" - - #Registry keys to delete if they aren't uninstalled by RemoveAppXPackage/RemoveAppXProvisionedPackage - "HKCR:\Extensions\ContractId\Windows.Launch\PackageId\46928bounde.EclipseManager_2.2.4.51_neutral__a5h4egax66k6y" - "HKCR:\Extensions\ContractId\Windows.Launch\PackageId\ActiproSoftwareLLC.562882FEEB491_2.6.18.18_neutral__24pqs290vpjk0" - "HKCR:\Extensions\ContractId\Windows.Launch\PackageId\Microsoft.PPIProjection_10.0.15063.0_neutral_neutral_cw5n1h2txyewy" - "HKCR:\Extensions\ContractId\Windows.Launch\PackageId\Microsoft.XboxGameCallableUI_1000.15063.0.0_neutral_neutral_cw5n1h2txyewy" - "HKCR:\Extensions\ContractId\Windows.Launch\PackageId\Microsoft.XboxGameCallableUI_1000.16299.15.0_neutral_neutral_cw5n1h2txyewy" - - #Scheduled Tasks to delete - "HKCR:\Extensions\ContractId\Windows.PreInstalledConfigTask\PackageId\Microsoft.MicrosoftOfficeHub_17.7909.7600.0_x64__8wekyb3d8bbwe" - - #Windows Protocol Keys - "HKCR:\Extensions\ContractId\Windows.Protocol\PackageId\ActiproSoftwareLLC.562882FEEB491_2.6.18.18_neutral__24pqs290vpjk0" - "HKCR:\Extensions\ContractId\Windows.Protocol\PackageId\Microsoft.PPIProjection_10.0.15063.0_neutral_neutral_cw5n1h2txyewy" - "HKCR:\Extensions\ContractId\Windows.Protocol\PackageId\Microsoft.XboxGameCallableUI_1000.15063.0.0_neutral_neutral_cw5n1h2txyewy" - "HKCR:\Extensions\ContractId\Windows.Protocol\PackageId\Microsoft.XboxGameCallableUI_1000.16299.15.0_neutral_neutral_cw5n1h2txyewy" - - #Windows Share Target - "HKCR:\Extensions\ContractId\Windows.ShareTarget\PackageId\ActiproSoftwareLLC.562882FEEB491_2.6.18.18_neutral__24pqs290vpjk0" - ) - - #This writes the output of each key it is removing and also removes the keys listed above. - ForEach ($Key in $Keys) { - Write-Host "Removing $Key from registry" - Remove-Item $Key -Recurse - } - } - - Function Protect-Privacy { - $ErrorActionPreference = 'silentlycontinue' - - Param([switch]$Debloat) - - #Creates a PSDrive to be able to access the 'HKCR' tree - New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT - - #Disables Windows Feedback Experience - Write-Host "Disabling Windows Feedback Experience program" - $Advertising = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AdvertisingInfo' - If (Test-Path $Advertising) { - Set-ItemProperty $Advertising Enabled -Value 0 -Verbose - } - - #Stops Cortana from being used as part of your Windows Search Function - Write-Host "Stopping Cortana from being used as part of your Windows Search Function" - $Search = 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\Windows Search' - If (Test-Path $Search) { - Set-ItemProperty $Search AllowCortana -Value 0 -Verbose - } - - #Stops the Windows Feedback Experience from sending anonymous data - Write-Host "Stopping the Windows Feedback Experience program" - $Period1 = 'HKCU:\Software\Microsoft\Siuf' - $Period2 = 'HKCU:\Software\Microsoft\Siuf\Rules' - $Period3 = 'HKCU:\Software\Microsoft\Siuf\Rules\PeriodInNanoSeconds' - If (!(Test-Path $Period3)) { - mkdir $Period1 - mkdir $Period2 - mkdir $Period3 - New-ItemProperty $Period3 PeriodInNanoSeconds -Value 0 -Verbose - } - - Write-Host "Adding Registry key to prevent bloatware apps from returning" - #Prevents bloatware applications from returning - $registryPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\CloudContent" - If (!(Test-Path $registryPath)) { - Mkdir $registryPath - New-ItemProperty $registryPath DisableWindowsConsumerFeatures -Value 1 -Verbose - } - - Write-Host "Setting Mixed Reality Portal value to 0 so that you can uninstall it in Settings" - $Holo = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Holographic' - If (Test-Path $Holo) { - Set-ItemProperty $Holo FirstRunSucceeded -Value 0 -Verbose - } - - #Disables live tiles - Write-Host "Disabling live tiles" - $Live = 'HKCU:\SOFTWARE\Policies\Microsoft\Windows\CurrentVersion\PushNotifications' - If (!(Test-Path $Live)) { - mkdir $Live - New-ItemProperty $Live NoTileApplicationNotification -Value 1 -Verbose - } - - #Turns off Data Collection via the AllowTelemtry key by changing it to 0 - Write-Host "Turning off Data Collection" - $DataCollection = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection' - If (Test-Path $DataCollection) { - Set-ItemProperty $DataCollection AllowTelemetry -Value 0 -Verbose - } - - #Disables People icon on Taskbar - Write-Host "Disabling People icon on Taskbar" - $People = 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\People' - If (Test-Path $People) { - Set-ItemProperty $People PeopleBand -Value 0 -Verbose - } - - #Disables suggestions on start menu - Write-Host "Disabling suggestions on the Start Menu" - $Suggestions = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager' - If (Test-Path $Suggestions) { - Set-ItemProperty $Suggestions SystemPaneSuggestionsEnabled -Value 0 -Verbose - } - - Write-Host "Removing CloudStore from registry if it exists" - $CloudStore = 'HKCUSoftware\Microsoft\Windows\CurrentVersion\CloudStore' - If (Test-Path $CloudStore) { - Stop-Process Explorer.exe -Force - Remove-Item $CloudStore - Start-Process Explorer.exe -Wait - } - - #Loads the registry keys/values below into the NTUSER.DAT file which prevents the apps from redownloading. Credit to a60wattfish - reg load HKU\Default_User C:\Users\Default\NTUSER.DAT - Set-ItemProperty -Path Registry::HKU\Default_User\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager -Name SystemPaneSuggestionsEnabled -Value 0 - Set-ItemProperty -Path Registry::HKU\Default_User\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager -Name PreInstalledAppsEnabled -Value 0 - Set-ItemProperty -Path Registry::HKU\Default_User\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager -Name OemPreInstalledAppsEnabled -Value 0 - reg unload HKU\Default_User - - #Disables scheduled tasks that are considered unnecessary - Write-Host "Disabling scheduled tasks" - Get-ScheduledTask -TaskName XblGameSaveTaskLogon | Disable-ScheduledTask - Get-ScheduledTask -TaskName XblGameSaveTask | Disable-ScheduledTask - Get-ScheduledTask -TaskName Consolidator | Disable-ScheduledTask - Get-ScheduledTask -TaskName UsbCeip | Disable-ScheduledTask - Get-ScheduledTask -TaskName DmClient | Disable-ScheduledTask - Get-ScheduledTask -TaskName DmClientOnScenarioDownload | Disable-ScheduledTask - } - - Function UnpinStart { - #Credit to Vikingat-Rage - #https://superuser.com/questions/1068382/how-to-remove-all-the-tiles-in-the-windows-10-start-menu - #Unpins all tiles from the Start Menu - Write-Host "Unpinning all tiles from the start menu" - (New-Object -Com Shell.Application). - NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}'). - Items() | - %{ $_.Verbs() } | - ?{$_.Name -match 'Un.*pin from Start'} | - %{$_.DoIt()} - } - - #This includes fixes by xsisbest - Function FixWhitelistedApps { - - Param([switch]$Debloat) - - If (!(Get-AppxPackage -AllUsers | Select Microsoft.Paint3D, Microsoft.MSPaint, Microsoft.WindowsCalculator, Microsoft.WindowsStore, Microsoft.MicrosoftStickyNotes, Microsoft.WindowsSoundRecorder, Microsoft.Windows.Photos)) { - - #Credit to abulgatz for the 4 lines of code - Get-AppxPackage -allusers Microsoft.Paint3D | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"} - Get-AppxPackage -allusers Microsoft.MSPaint | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"} - Get-AppxPackage -allusers Microsoft.WindowsCalculator | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"} - Get-AppxPackage -allusers Microsoft.WindowsStore | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"} - Get-AppxPackage -allusers Microsoft.MicrosoftStickyNotes | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"} - Get-AppxPackage -allusers Microsoft.WindowsSoundRecorder | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"} - Get-AppxPackage -allusers Microsoft.Windows.Photos | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"} - } - } - - Function CheckDMWService { - - Param([switch]$Debloat) - - If (Get-Service dmwappushservice | Where-Object {$_.StartType -eq "Disabled"}) { - Set-Service dmwappushservice -StartupType Automatic - } - - If (Get-Service dmwappushservice | Where-Object {$_.Status -eq "Stopped"}) { - Start-Service dmwappushservice - } - } - - Function CheckInstallService { - - If (Get-Service InstallService | Where-Object {$_.Status -eq "Stopped"}) { - Start-Service InstallService - Set-Service InstallService -StartupType Automatic - } - } - - Begin-SysPrep - Write-Host "Removing bloatware apps." - Start-Debloat - Write-Host "Removing leftover bloatware registry keys." - Remove-Keys - Write-Host "Checking to see if any Whitelisted Apps were removed, and if so re-adding them." - FixWhitelistedApps - Write-Host "Stopping telemetry, disabling unneccessary scheduled tasks, and preventing bloatware from returning." - Protect-Privacy - Write-Host "Unpinning tiles from the Start Menu." - UnpinStart - Write-Host "Stopping Edge from taking over as the default PDF Viewer." - Write-Host "Checking to make sure that the service 'dmwappushservice' has been started." - CheckDMWService - Write-Host "Setting the 'InstallService' Windows service back to started and setting the Startup Type to 'Automatic'." - CheckInstallService - Write-Host "Finished all tasks. `n" - - }) $RevertChange.Add_Click( { $ErrorActionPreference = 'silentlycontinue' #This function will revert the changes you made when running the Start-Debloat function.