2017-12-12 01:38:03 +00:00
#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.
2018-03-16 04:25:00 +00:00
param (
2018-10-07 23:17:43 +00:00
[ switch ] $Debloat , [ switch ] $SysPrep
2018-03-16 04:25:00 +00:00
)
2018-09-14 03:01:03 +00:00
2017-12-29 04:59:05 +00:00
Function Begin-SysPrep {
param ( [ switch ] $SysPrep )
2018-10-07 23:25:26 +00:00
Write-Verbose -Message ( 'Starting Sysprep Fixes' )
# Disable Windows Store Automatic Updates
2019-02-23 22:28:44 +00:00
<# Write-Verbose -Message "Adding Registry key to Disable Windows Store Automatic Updates"
2018-10-07 23:25:26 +00:00
$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
}
#Stop WindowsStore Installer Service and set to Disabled
Write-Verbose -Message ( 'Stopping InstallService' )
2019-02-23 22:28:44 +00:00
Stop-Service InstallService
2019-03-05 14:10:32 +00:00
#>
}
2018-10-05 03:59:45 +00:00
2018-10-07 23:17:43 +00:00
#Creates a PSDrive to be able to access the 'HKCR' tree
New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT
Function Start-Debloat {
param ( [ switch ] $Debloat )
2018-10-05 03:59:45 +00:00
#Removes AppxPackages
#Credit to Reddit user /u/GavinEke for a modified version of my whitelist code
2019-01-26 04:36:32 +00:00
[ regex ] $WhitelistedApps = ' Microsoft . ScreenSketch | Microsoft . Paint3D | Microsoft . WindowsCalculator | Microsoft . WindowsStore | Microsoft . Windows . Photos | CanonicalGroupLimited . UbuntuonWindows | `
2019-03-11 10:17:27 +00:00
Microsoft . MicrosoftStickyNotes | Microsoft . MSPaint | Microsoft . WindowsCamera | . NET | Framework | Microsoft . HEIFImageExtension | Microsoft . ScreenSketch | Microsoft . StorePurchaseApp | `
Microsoft . VP9VideoExtensions | Microsoft . WebMediaExtensions | Microsoft . WebpImageExtension | Microsoft . DesktopAppInstaller '
2018-10-05 03:59:45 +00:00
Get-AppxPackage -AllUsers | Where-Object { $_ . Name -NotMatch $WhitelistedApps } | Remove-AppxPackage -ErrorAction SilentlyContinue
2018-10-08 18:22:09 +00:00
# Run this again to avoid error on 1803 or having to reboot.
Get-AppxPackage -AllUsers | Where-Object { $_ . Name -NotMatch $WhitelistedApps } | Remove-AppxPackage -ErrorAction SilentlyContinue
2019-03-11 10:17:27 +00:00
$AppxRemoval = Get-AppxProvisionedPackage -Online | Where-Object { $_ . PackageName -NotMatch $WhitelistedApps }
ForEach ( $App in $AppxRemoval ) {
Remove-AppxProvisionedPackage -Online -PackageName $App . PackageName
}
2017-12-12 01:38:03 +00:00
}
2017-12-29 04:59:05 +00:00
2017-12-12 01:38:03 +00:00
Function Remove-Keys {
2018-10-07 23:17:43 +00:00
Param ( [ switch ] $Debloat )
2018-09-09 05:46:31 +00:00
2018-10-05 03:59:45 +00:00
#These are the registry keys that it will delete.
2018-10-07 23:17:43 +00:00
2018-10-05 03:59:45 +00:00
$Keys = @ (
2018-10-07 23:17:43 +00:00
2018-10-05 03:59:45 +00:00
#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 "
2018-10-07 23:17:43 +00:00
2018-10-05 03:59:45 +00:00
#Windows File
" HKCR:\Extensions\ContractId\Windows.File\PackageId\ActiproSoftwareLLC.562882FEEB491_2.6.18.18_neutral__24pqs290vpjk0 "
2018-10-07 23:17:43 +00:00
2018-10-05 03:59:45 +00:00
#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 "
2018-10-07 23:17:43 +00:00
2018-10-05 03:59:45 +00:00
#Scheduled Tasks to delete
" HKCR:\Extensions\ContractId\Windows.PreInstalledConfigTask\PackageId\Microsoft.MicrosoftOfficeHub_17.7909.7600.0_x64__8wekyb3d8bbwe "
2018-10-07 23:17:43 +00:00
2018-10-05 03:59:45 +00:00
#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 "
2018-10-07 23:17:43 +00:00
2018-10-05 03:59:45 +00:00
#Windows Share Target
" HKCR:\Extensions\ContractId\Windows.ShareTarget\PackageId\ActiproSoftwareLLC.562882FEEB491_2.6.18.18_neutral__24pqs290vpjk0 "
)
2018-10-07 23:17:43 +00:00
2018-10-05 03:59:45 +00:00
#This writes the output of each key it is removing and also removes the keys listed above.
ForEach ( $Key in $Keys ) {
Write-Output " Removing $Key from registry "
Remove-Item $Key -Recurse -ErrorAction SilentlyContinue
2017-12-12 01:38:03 +00:00
}
}
2018-10-07 23:17:43 +00:00
2017-12-12 01:38:03 +00:00
Function Protect-Privacy {
2018-10-07 23:17:43 +00:00
Param ( [ switch ] $Debloat )
2017-12-12 01:38:03 +00:00
2018-10-05 03:59:45 +00:00
#Creates a PSDrive to be able to access the 'HKCR' tree
New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT
2018-10-07 23:17:43 +00:00
2018-10-05 03:59:45 +00:00
#Disables Windows Feedback Experience
Write-Output " Disabling Windows Feedback Experience program "
$Advertising = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AdvertisingInfo'
If ( Test-Path $Advertising ) {
Set-ItemProperty $Advertising -Name Enabled -Value 0 -Verbose
}
2018-10-07 23:17:43 +00:00
2018-10-05 03:59:45 +00:00
#Stops Cortana from being used as part of your Windows Search Function
Write-Output " 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
}
2018-10-07 23:17:43 +00:00
2018-10-05 03:59:45 +00:00
#Stops the Windows Feedback Experience from sending anonymous data
Write-Output " Stopping the Windows Feedback Experience program "
$Period1 = 'HKCU:\Software\Microsoft\Siuf'
$Period2 = 'HKCU:\Software\Microsoft\Siuf\Rules'
$Period3 = 'HKCU:\Software\Microsoft\Siuf\Rules\PeriodInNanoSeconds'
2018-10-07 23:17:43 +00:00
If ( ! ( Test-Path $Period3 ) ) {
2018-10-05 03:59:45 +00:00
mkdir $Period1 -ErrorAction SilentlyContinue
mkdir $Period2 -ErrorAction SilentlyContinue
mkdir $Period3 -ErrorAction SilentlyContinue
New-ItemProperty $Period3 -Name PeriodInNanoSeconds -Value 0 -Verbose -ErrorAction SilentlyContinue
}
2018-10-07 23:17:43 +00:00
2018-10-05 03:59:45 +00:00
Write-Output " 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
2018-10-07 23:17:43 +00:00
}
2018-10-05 03:59:45 +00:00
Write-Output " Setting Mixed Reality Portal value to 0 so that you can uninstall it in Settings "
2018-10-07 23:17:43 +00:00
$Holo = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Holographic'
2018-10-05 03:59:45 +00:00
If ( Test-Path $Holo ) {
Set-ItemProperty $Holo -Name FirstRunSucceeded -Value 0 -Verbose
}
2018-10-07 23:17:43 +00:00
2018-10-05 03:59:45 +00:00
#Disables live tiles
Write-Output " Disabling live tiles "
2018-10-07 23:17:43 +00:00
$Live = 'HKCU:\SOFTWARE\Policies\Microsoft\Windows\CurrentVersion\PushNotifications'
2018-10-05 03:59:45 +00:00
If ( ! ( Test-Path $Live ) ) {
2018-10-07 23:17:43 +00:00
mkdir $Live -ErrorAction SilentlyContinue
2018-10-05 03:59:45 +00:00
New-ItemProperty $Live -Name NoTileApplicationNotification -Value 1 -Verbose
}
2018-10-07 23:17:43 +00:00
2018-10-05 03:59:45 +00:00
#Turns off Data Collection via the AllowTelemtry key by changing it to 0
Write-Output " Turning off Data Collection "
2018-10-07 23:17:43 +00:00
$DataCollection = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection'
2018-10-05 03:59:45 +00:00
If ( Test-Path $DataCollection ) {
Set-ItemProperty $DataCollection -Name AllowTelemetry -Value 0 -Verbose
}
2018-10-07 23:17:43 +00:00
2018-10-05 03:59:45 +00:00
#Disables People icon on Taskbar
Write-Output " Disabling People icon on Taskbar "
2019-01-26 04:01:24 +00:00
$People = 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\People'
If ( Test-Path $People ) {
Set-ItemProperty $People -Name PeopleBand -Value 0 -Verbose
2018-10-05 03:59:45 +00:00
}
#Disables suggestions on start menu
Write-Output " Disabling suggestions on the Start Menu "
2018-10-07 23:17:43 +00:00
$Suggestions = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager'
2018-10-05 03:59:45 +00:00
If ( Test-Path $Suggestions ) {
Set-ItemProperty $Suggestions -Name SystemPaneSuggestionsEnabled -Value 0 -Verbose
}
2018-12-01 19:10:32 +00:00
Write-Output " Removing CloudStore from registry if it exists "
2020-03-15 00:41:11 +00:00
$CloudStore = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\CloudStore'
2018-12-01 19:10:32 +00:00
If ( Test-Path $CloudStore ) {
Stop-Process Explorer . exe -Force
2020-03-15 00:41:11 +00:00
Remove-Item $CloudStore -Recurse -Force
2018-12-01 19:10:32 +00:00
Start-Process Explorer . exe -Wait
}
2018-10-05 03:59:45 +00:00
#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
2018-10-07 23:17:43 +00:00
#Disables scheduled tasks that are considered unnecessary
2018-10-05 03:59:45 +00:00
Write-Output " Disabling scheduled tasks "
2018-10-07 23:17:43 +00:00
#Get-ScheduledTask -TaskName XblGameSaveTaskLogon | Disable-ScheduledTask -ErrorAction SilentlyContinue
2018-10-05 03:59:45 +00:00
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
2017-12-12 01:38:03 +00:00
}
2018-07-25 15:36:27 +00:00
2018-10-07 23:17:43 +00:00
#This includes fixes by xsisbest
2018-02-19 15:53:37 +00:00
Function FixWhitelistedApps {
2018-09-09 05:46:31 +00:00
2018-10-07 23:17:43 +00:00
Param ( [ switch ] $Debloat )
If ( ! ( Get-AppxPackage -AllUsers | Select Microsoft . Paint3D , Microsoft . MSPaint , Microsoft . WindowsCalculator , Microsoft . WindowsStore , Microsoft . MicrosoftStickyNotes , Microsoft . WindowsSoundRecorder , Microsoft . Windows . Photos ) ) {
2018-09-29 22:12:53 +00:00
#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 " }
2018-10-07 23:17:43 +00:00
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 " } }
2018-10-05 03:59:45 +00:00
}
2018-02-19 15:53:37 +00:00
2018-11-11 03:30:03 +00:00
Function CheckDMWService {
2018-10-12 01:36:04 +00:00
Param ( [ switch ] $Debloat )
2018-12-23 23:00:32 +00:00
If ( Get-Service -Name dmwappushservice | Where-Object { $_ . StartType -eq " Disabled " } ) {
Set-Service -Name dmwappushservice -StartupType Automatic }
If ( Get-Service -Name dmwappushservice | Where-Object { $_ . Status -eq " Stopped " } ) {
Start-Service -Name dmwappushservice }
2018-12-23 23:02:57 +00:00
}
2018-10-12 01:36:04 +00:00
2018-11-10 00:42:31 +00:00
Function CheckInstallService {
Param ( [ switch ] $Debloat )
2018-11-11 03:30:03 +00:00
If ( Get-Service -Name InstallService | Where-Object { $_ . Status -eq " Stopped " } ) {
Start-Service -Name InstallService
Set-Service -Name InstallService -StartupType Automatic
}
}
2018-11-10 00:42:31 +00:00
2017-12-29 04:59:05 +00:00
Write-Output " Initiating Sysprep "
2018-10-07 23:17:43 +00:00
Begin-SysPrep
2017-12-12 01:38:03 +00:00
Write-Output " Removing bloatware apps. "
2018-10-07 23:17:43 +00:00
Start-Debloat
2017-12-12 01:38:03 +00:00
Write-Output " Removing leftover bloatware registry keys. "
2018-10-07 23:17:43 +00:00
Remove-Keys
2018-02-19 15:53:37 +00:00
Write-Output " Checking to see if any Whitelisted Apps were removed, and if so re-adding them. "
2018-10-07 23:17:43 +00:00
FixWhitelistedApps
2017-12-12 01:38:03 +00:00
Write-Output " Stopping telemetry, disabling unneccessary scheduled tasks, and preventing bloatware from returning. "
2018-10-07 23:17:43 +00:00
Protect-Privacy
#Write-Output "Stopping Edge from taking over as the default PDF Viewer."
#Stop-EdgePDF
2018-11-11 03:30:03 +00:00
CheckDMWService
CheckInstallService
2017-12-12 01:38:03 +00:00
Write-Output " Finished all tasks. "