Debloat Windows 10

This topic contains 3 replies, has 3 voices, and was last updated by  Damian 3 weeks, 6 days ago.

  • Author
    Posts
  • #99790

    Damian
    Participant

    https://github.com/EntityTech/Windows-10-Debloat.git

    I was just tired of all the junk Microsoft loads your Win 10 up with when it's installed or booted up for the first time, so I started playing around with a few things in powershell and came up with this.

    Please check out my code and critique if you can and if you see room for improvement then let me know

    Also hopefully I'm posting this code correctly below

    #########
    ##Allows the script to run with right click "run with powershell"
    #########
    
    Add-Type -AssemblyName PresentationCore,PresentationFramework
    If (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]'Administrator'))
    {
      Start-Process -FilePath powershell.exe -ArgumentList ("-NoProfile -ExecutionPolicy Bypass -File `"{0}`"" -f $PSCommandPath) -Verb RunAs
      Exit
    }
    
    #########
    ##Ignore Error messages and setting some variables
    #########
    
    $ErrorActionPreference = 'silentlycontinue'
    $ButtonType = [Windows.MessageBoxButton]::YesNo
    $ErrorIcon = [Windows.MessageBoxImage]::Error
    $OdBody = 'Do you want to get rid of OneDrive?'
    $WarnBody = 'Warning, this will remove ALL default Windows 10 apps where you will ONLY have the Windows Store left, do you want to continue?'
    $MessageTitle = 'Confirm Delete'
    $WarnIcon = [Windows.MessageBoxImage]::Warning
    
    #########
    ##Warning about the script
    #########
    
    $StartInput = [Windows.MessageBox]::Show($WarnBody,$MessageTitle,$ButtonType,$WarnIcon)
    If ($StartInput -eq 'Yes')  
    {
    
    #########
    ##Uninstall Bloat and all default windows apps except the store and prevents them from 
    ##coming back on future users but does not delete the store.
    #########
    
    Get-AppxPackage -AllUsers | Where {($_.Name -notlike '*store*')} | Remove-AppxPackage
    
    Get-AppxProvisionedPackage -Online | Where {($_.Name -notlike '*store*')} | Remove-AppxProvisionedPackage -Online
    
    ########
    ##The Registry path to prevent more apps from reinstalling later on.
    ########
    $regPath = 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\CloudContent'
    $regCDM = 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager'
    
    New-Item -Path $regPath -Force
    New-ItemProperty -Path $regPath -Name DisableWindowsConsumerFeatures -Value 1 -Force
    Set-ItemProperty -Path $regCDM -Name ContentDeliveryAllowed -Value 0 -Force
    Set-ItemProperty -Path $regCDM -Name OemPreInstalledAppsEnabled -Value 0 -Force
    Set-ItemProperty -Path $regCDM -Name PreInstalledAppsEnabled -Value 0 -Force
    Set-ItemProperty -Path $regCDM -Name PreInstalledAppsEverEnabled -Value 0 -Force
    Set-ItemProperty -Path $regCDM -Name SilentInstalledAppsEnabled -Value 0 -Force
    Set-ItemProperty -Path $regCDM -Name SystemPaneSuggestionsEnabled -Value 0 -Force
    Remove-Item -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager\SuggestedApps
    }
    ########
    ##Prompt to remove OneDrive from the computer.
    ########
    
    $OdInput = [Windows.MessageBox]::Show($OdBody,$MessageTitle,$ButtonType,$ErrorIcon)
    
    If ($OdInput -eq 'Yes')  
    {
        New-PSDrive -PSProvider 'Registry' -Root 'HKEY_CLASSES_ROOT' -Name 'HKCR'
        $regOneDrive = 'HKCR:\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}'
        $regTwoDrive = 'HKCR:\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}'
        $PathHereOne = Test-Path -Path $regOneDrive
        $PathHereTwo = Test-Path -Path $regTwoDrive
    				
        Write-Output -InputObject 'Stopping OneDrive.'
        & "$env:windir\system32\taskkill.exe" /F /IM 'OneDrive.exe'
        & "$env:windir\system32\taskkill.exe" /F /IM 'explorer.exe'
    
        Write-Output -InputObject 'Uninstalling OneDrive from the computer.'
        If (Test-Path -Path "$env:systemroot\System32\OneDriveSetup.exe") 
        {
          & "$env:systemroot\System32\OneDriveSetup.exe" /uninstall
        }
        If (Test-Path -Path "$env:systemroot\SysWOW64\OneDriveSetup.exe") 
        {
          & "$env:systemroot\SysWOW64\OneDriveSetup.exe" /uninstall
        }
    
        Write-Output -InputObject 'Getting rid of extra files.'
        Remove-Item -Recurse -Force -Path "$env:localappdata\Microsoft\OneDrive"
        Remove-Item -Recurse -Force -Path "$env:programdata\Microsoft OneDrive"
        Remove-Item -Recurse -Force -Path "$env:HOMEDRIVE\OneDriveTemp"
        Remove-Item -Recurse -Force -Path "$env:userprofile\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk"
        Remove-Item -Recurse -Force -Path "$env:userprofile\OneDrive"
        Remove-Item -Recurse -Force -Path "$env:userprofile\Links\OneDrive"
        Remove-Item -Recurse -Force -Path "$env:windir\SysWOW64\OneDriveSetup"
    
    
        Write-Output -InputObject 'Checking to remove OneDrive from sidebar in windows explorer.'
        If ($PathHereOne -eq $True) 
        {
          Set-ItemProperty -Path $regOneDrive -Name System.IsPinnedToNameSpaceTree -Value 0 -Force
        }
        If ($PathHereOne -eq $False) 
        {
          New-Item -Path $regOneDrive -Force
          New-ItemProperty -Path $regOneDrive -Name System.IsPinnedToNameSpaceTree -Value 0 -Force
        }
        If ($PathHereTwo -eq $True) 
        {
          Set-ItemProperty -Path $regTwoDrive -Name System.IsPinnedToNameSpaceTree -Value 0 -Force
        }
        If ($PathHereTwo -eq $False) 
        {
          New-Item -Path $regTwoDrive -Force
          New-ItemProperty -Path $regTwoDrive -Name System.IsPinnedToNameSpaceTree -Value 0 -Force
        }
        Write-Output -InputObject 'Restarting explorer that got shut down before.'
        & "$env:windir\explorer.exe"
        Remove-PSDrive -Name 'HKCR'
    }
    ########
    ##Returns the execution policy to default
    ########
    Set-ExecutionPolicy -ExecutionPolicy Restricted -Force
    
  • #99798

    Simon B
    Participant

    Why not just use DISM on your install wim and remove the packages you don't want from there rather than doing a tidy up post deployment ?

  • #99814

    Maurice L
    Participant

    Do you realize that you're also removing stuff like the Calculator, Edge, Paint, SoundRecorder etc with this script? Not sure if that is what you (or your users) actually want.

  • #99871

    Damian
    Participant

    Well that's what this is aimed at, I could use DISM if I was managing a bunch of computers but this is more for people who got a computer anywhere and doesn't want it loaded up with all the junk apps Windows comes pre loaded with. So for the most part this is supposed to be post deployment

    And yes, if you run the script I have a GUI popup warning you about losing ALL apps where ONLY the windows store will be left.

    **
    $WarnBody = 'Warning, this will remove ALL default Windows 10 apps where you will ONLY have the Windows Store left, do you want to continue?'
    **

    I can probably add another line telling them they'll need to reinstall those apps they do use like Calc or Mail but I thought the "ALL app except Store" warning was enough

You must be logged in to reply to this topic.