Skip to content

Instantly share code, notes, and snippets.

@crast
Last active June 4, 2022 02:48
Show Gist options
  • Save crast/8a298fc89c4fe07121b940323d6e1655 to your computer and use it in GitHub Desktop.
Save crast/8a298fc89c4fe07121b940323d6e1655 to your computer and use it in GitHub Desktop.
Windows junk removal

Windows 10 Junk Removal

This is a powershell script that does a number of things to remove some extra fluff from even fresh windows installs though you can also run it on existing windows installs. If you run this before ever hooking up ethernet and then reboot, you can even avoid Candy Crush etc from showing up in the first place.

I use this script regularly on all new installs but read the script and run at your own risk

Summary

The important things it does:

  1. Disables some of the suggested sections from the start menu and all initial "pins" like MS word/OneNote etc.
  2. Disables all of the ways windows can "suggest" apps that then show up in your start menu either installed or partially installed
  3. Removes OneDrive and also removes a number of windows apps (see the list near the bottom to customize to your liking)
  4. Stops printer autoinstall

How To Run

Because of permissions on powershell scripts in new systems being a hassle to modify, I usually just run this with Win-X then A followed by pasting the contents of the script. But if you want to set up a policy modification to use this, do it and let me know :)

############################
## pshell/magic start menu.ps1
###########################
#Delete layout file if it already exists
If(Test-Path C:\Windows\StartLayout.xml)
{
Remove-Item C:\Windows\StartLayout.xml
}
#Creates the blank layout file
echo "<LayoutModificationTemplate xmlns:defaultlayout=""http://schemas.microsoft.com/Start/2014/FullDefaultLayout"" xmlns:start=""http://schemas.microsoft.com/Start/2014/StartLayout"" Version=""1"" xmlns=""http://schemas.microsoft.com/Start/2014/LayoutModification"">" >> C:\Windows\StartLayout.xml
echo " <LayoutOptions StartTileGroupCellWidth=""6"" />" >> C:\Windows\StartLayout.xml
echo " <DefaultLayoutOverride>" >> C:\Windows\StartLayout.xml
echo " <StartLayoutCollection>" >> C:\Windows\StartLayout.xml
echo " <defaultlayout:StartLayout GroupCellWidth=""6"" />" >> C:\Windows\StartLayout.xml
echo " </StartLayoutCollection>" >> C:\Windows\StartLayout.xml
echo " </DefaultLayoutOverride>" >> C:\Windows\StartLayout.xml
echo "</LayoutModificationTemplate>" >> C:\Windows\StartLayout.xml
$regAliases = @("HKLM", "HKCU")
#Assign the start layout and force it to apply with "LockedStartLayout" at both the machine and user level
foreach ($regAlias in $regAliases){
$basePath = $regAlias + ":\SOFTWARE\Policies\Microsoft\Windows"
$keyPath = $basePath + "\Explorer"
IF(!(Test-Path -Path $keyPath)) {
New-Item -Path $basePath -Name "Explorer"
}
Set-ItemProperty -Path $keyPath -Name "LockedStartLayout" -Value 1
Set-ItemProperty -Path $keyPath -Name "StartLayoutFile" -Value "C:\Windows\StartLayout.xml"
}
#Restart Explorer, open the start menu (necessary to load the new layout), and give it a few seconds to process
Stop-Process -name explorer
Start-Sleep -s 5
$wshell = New-Object -ComObject wscript.shell; $wshell.SendKeys('^{ESCAPE}')
Start-Sleep -s 5
#Enable the ability to pin items again by disabling "LockedStartLayout"
foreach ($regAlias in $regAliases){
$basePath = $regAlias + ":\SOFTWARE\Policies\Microsoft\Windows"
$keyPath = $basePath + "\Explorer"
Set-ItemProperty -Path $keyPath -Name "LockedStartLayout" -Value 0
}
#Restart Explorer and delete the layout file
Stop-Process -name explorer
Remove-Item C:\Windows\StartLayout.xml
############################
## pshell/onedrive.ps1
###########################
cd C:\Windows\SysWOW64
.\OneDriveSetup.exe /uninstall
############################
## pshell/printer autoinstall.ps1
###########################
Function Stop-PrinterAutoInstall
{
New-Item "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\NcdAutoSetup\Private" -Force | New-ItemProperty -Name "AutoSetup" -Value 0 -Force | Out-Null
$PrinterInstall = Get-ItemProperty -Path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\NcdAutoSetup\Private" -Name "AutoSetup"
if ($PrinterInstall.AutoSetup -eq 0)
{
Write-Host "Printer AutoSetup Disabled"
}
Else {Write-Host "Printer AutoSetup still enabled, please setup manually"}
}
Function Start-PrinterAutoInstall
{
$PrinterInstall = Get-ItemProperty -Path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\NcdAutoSetup\Private" -Name "AutoSetup"
if ($PrinterInstall.AutoSetup -ne 1)
{
Set-ItemProperty -Path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\NcdAutoSetup\Private" -Name "AutoSetup" -Value 1
Write-Host "Printer AutoSetup enabled"
}
Else {Write-Host "Printer AutoSetup already Enabled"}
}
Stop-PrinterAutoInstall
############################
## pshell/reg_system.ps1
###########################
# disable all the ways MS can 'suggest' or show Candy Crush, etc in Start
New-Item -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows -Name CloudContent
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\CloudContent -Name DisableWindowsConsumerFeatures -Value 1 -Type DWord -Force
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection -Name AllowTelemetry -Value 0 -Type DWord
Set-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager -Name SilentInstalledAppsEnabled -Value 0 -Type DWord
Set-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager -Name SystemPaneSuggestionsEnabled -Value 0 -Type DWord
# Microsoft Edge harassment
New-Item -Path HKLM:\SOFTWARE\Policies\Microsoft -name "MicrosoftEdge"
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\MicrosoftEdge -Name PreventFirstRunPage -Value 1 -Type DWord
# Telemetry / customization of suggested apps
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection -Name AllowTelemetry -Value 0 -Type DWord
# automatically getting Windows Store Apps for printers and other dumb things
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Device Metadata" -Name "PreventDeviceMetadataFromNetwork" -Value 1 -Type Dword -Force
# Timezone QOL
Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control\TimeZoneInformation -Name RealTimeIsUniversal -Value 1 -Type QWord
# "Finish setting up your device" every 3 days
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\UserProfileEngagement -Name "ScoobeSystemSettingEnabled" -Value 0 -Type DWord -Force
# News/Interests in taskbar
Set-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Feeds -Name "ShellFeedsTaskbarViewMode" -Value 2 -Type DWord -Force
# Search highlights (cutesy icons) in taskbar search
New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows" -Name "Windows Search"
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Windows Search" -Name EnableDynamicContentInWSB -Type DWord -Value 0 -Force
############################
## pshell/reg_user.ps1
###########################
# Driveby app install
Set-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager -Name SilentInstalledAppsEnabled -Value 0 -Type DWord
Set-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager -Name SystemPaneSuggestionsEnabled -Value 0 -Type DWord
# "Finish setting up your device"
New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion -Name "UserProfileEngagement"
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\UserProfileEngagement -Name "ScoobeSystemSettingEnabled" -Value 0 -Type DWord -Force
# News/Interests in taskbar
Set-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Feeds -Name "ShellFeedsTaskbarViewMode" -Value 2 -Type DWord -Force
############################
## pshell/remove some windows apps.ps1
###########################
$appsToRemove = @(
# These are the apps I remove. Delete lines if you want to keep these apps.
# See the bottom of the script for more apps to remove if you want
"Microsoft.3DBuilder",
"Microsoft.Appconnector",
"Microsoft.BingFinance",
"Microsoft.BingNews",
"Microsoft.BingWeather",
"Microsoft.CommsPhone",
"Microsoft.ConnectivityStore",
"Microsoft.DesktopAppInstaller",
"Microsoft.Getstarted",
"Microsoft.Messaging",
"Microsoft.Microsoft3DViewer",
"Microsoft.MicrosoftOfficeHub",
"Microsoft.MicrosoftStickyNotes",
"Microsoft.MixedReality.Portal",
"Microsoft.Office.OneNote",
"Microsoft.Office.Sway",
"Microsoft.OneConnect",
"Microsoft.People",
"Microsoft.SkypeApp",
"Microsoft.MicrosoftSolitaireCollection",
"Microsoft.StorePurchaseApp",
"Microsoft.Wallet",
"Microsoft.WindowsAlarms",
"Microsoft.WindowsCamera",
"microsoft.windowscommunicationsapps",
"Microsoft.WindowsMaps",
"Microsoft.WindowsPhone",
"Microsoft.WindowsSoundRecorder",
"Microsoft.YourPhone",
# Here's more apps you may be interested in removing. Remove the first "#" to enable them.
#
# "Microsoft.MSPaint", # best dang thing ever
# "Microsoft.ScreenSketch", # For taking screenshots mostly
# "Microsoft.WindowsStore", # Windows Store: not recommended to remove
# "Microsoft.Windows.Photos", # Actually useful for looking at folders of photos
#
# "Microsoft.Xbox.TCUI", # All of the Xbox stuff; don't remove if you use GamePass
# "Microsoft.XboxApp",
# "Microsoft.XboxGameOverlay",
# "Microsoft.XboxGamingOverlay",
# "Microsoft.XboxIdentityProvider",
# "Microsoft.XboxSpeechToTextOverlay",
#
# "Microsoft.ZuneMusic", # Groove Music
# "Microsoft.ZuneVideo", # Movie Player, pretty dang useful
"This.Line.Is.Ignored"
)
Get-AppxProvisionedPackage -Online | % { if($_.DisplayName -in $appsToRemove){ echo $_.PackageName; Remove-AppxPackage -AllUsers $_.PackageName } }
# Here's some additional things you can run in a _non-administrator_ powershell, per-user, just to make sure your personal settings are good.
# Driveby app install
Set-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager -Name SilentInstalledAppsEnabled -Value 0 -Type DWord
Set-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager -Name SystemPaneSuggestionsEnabled -Value 0 -Type DWord
# "Finish setting up your device"
New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion -Name "UserProfileEngagement"
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\UserProfileEngagement -Name "ScoobeSystemSettingEnabled" -Value 0 -Type DWord -Force
# News/Interests in taskbar
Set-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Feeds -Name "ShellFeedsTaskbarViewMode" -Value 2 -Type DWord -Force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment