Cleaned up script and added comments to improve readability

This commit is contained in:
Raphire
2023-08-03 22:24:27 +02:00
parent 8ec9522885
commit 1ff465bc28
4 changed files with 109 additions and 53 deletions

14
Menus/DefaultSettings.txt Normal file
View File

@@ -0,0 +1,14 @@
-------------------------------------------------------------------------------------------
Win11Debloat Script - Setup
-------------------------------------------------------------------------------------------
Win11Debloat will make the following changes:
- Remove bloatware apps.
- Disable telemetry, diagnostic data & targeted ads.
- Disable bing search & cortana in windows search.
- Disable tips & tricks on the lockscreen. (This may change your lockscreen wallpaper to the default)
- Disable tips, tricks and suggestions in the start menu and settings, and ads in windows explorer.
- Show file extensions for known file types.
- Disable the widget service & hide the widget (news and interests) icon from the taskbar.
- Hide the Chat (meet now) icon from the taskbar.
- Hide the 3D objects folder in windows explorer. (Windows 10 only)

40
Menus/Info.txt Normal file
View File

@@ -0,0 +1,40 @@
-------------------------------------------------------------------------------------------
Win11Debloat - Information
-------------------------------------------------------------------------------------------
Win11Debloat is a simple and lightweight powershell script that removes pre-installed
windows bloatware apps, disables telemetry and declutters the experience by disabling
or removing intrusive interface elements, ads and context menu items. No need to
painstakingly go through all the settings yourself, or removing apps one by one!
-------------------------------------------------------------------------------------------
Using the default configuration the script will
-------------------------------------------------------------------------------------------
- Remove bloatware apps, the list can be found in the 'Appslist.txt' file.
- Disable telemetry, diagnostic data & targeted ads.
- Disable bing search & cortana in windows search.
- Disable tips & tricks on the lockscreen. (This may change your lockscreen wallpaper to the default)
- Disable tips, tricks and suggestions in the start menu and settings, and ads in windows explorer.
- Show file extensions for known file types.
- Disable the widget service & hide the widget (news and interests) icon from the taskbar.
- Hide the Chat (meet now) icon from the taskbar.
- Hide the 3D objects folder in windows explorer. (Windows 10 only)
-------------------------------------------------------------------------------------------
Using the custom mode you can
-------------------------------------------------------------------------------------------
- Remove bloatware apps, the list can be found in the 'Appslist.txt' file.
- Remove gaming-related apps, the list can be found in the 'GamingAppslist.txt' file.
- Disable telemetry, diagnostic data & targeted ads.
- Disable bing search & cortana in windows search.
- Disable tips & tricks on the lockscreen. (This may change your lockscreen wallpaper to the default)
- Disable tips, tricks and suggestions in the start menu and settings, and ads in windows explorer.
- Show hidden files, folders and drives.
- Show file extensions for known file types.
- Align taskbar icons to the left. (Windows 11 only)
- Hide or change the search icon/box on the taskbar. (Windows 11 only)
- Disable the widget service & hide the widget (news and interests) icon from the taskbar.
- Hide the Chat (meet now) icon from the taskbar.
- Hide the 3D objects, music or onedrive folders in windows explorer. (Windows 10 only)
- Hide the 'Include in library', 'Give access to' and 'Share' options in the context menu. (Windows 10 only)

9
Menus/Menu.txt Normal file
View File

@@ -0,0 +1,9 @@
-------------------------------------------------------------------------------------------
Win11Debloat Script - Setup
-------------------------------------------------------------------------------------------
(1) Run Win11Debloat with the default settings
(2) Custom mode: Manually select what changes you want Win11Debloat to make
(0) Show information about the script

View File

@@ -38,7 +38,8 @@ param
[Parameter(ValueFromPipeline = $true)][switch]$HideShare
)
# Removes all apps in the list
# Reads list of apps from file and removes them for all user accounts and from the OS image.
function RemoveApps {
param(
$appsFile,
@@ -47,25 +48,32 @@ function RemoveApps {
Write-Output $message
# Get list of apps from file at the path provided, and remove them one by one
Foreach ($app in (Get-Content -Path $appsFile | Where-Object { $_ -notmatch '^#.*' -and $_ -notmatch '^\s*$' } ))
{
# Remove any spaces before and after the Appname
$app = $app.Trim()
# Remove any comments from the Appname
if (-Not ($app.IndexOf('#') -eq -1)) {
$app = $app.Substring(0, $app.IndexOf('#'))
}
# Remove any remaining spaces from the Appname
if (-Not ($app.IndexOf(' ') -eq -1)) {
$app = $app.Substring(0, $app.IndexOf(' '))
}
Write-Output "Attempting to remove $app"
# Remove installed app for all existing users
Get-AppxPackage -Name $app -AllUsers | Remove-AppxPackage
# Remove provisioned app from OS image, so the app won't be installed for any new users
Get-AppxProvisionedPackage -Online | Where-Object { $_.PackageName -like $app } | ForEach-Object { Remove-ProvisionedAppxPackage -Online -AllUsers -PackageName $_.PackageName }
}
}
# Import & execute regfile
function RegImport {
param
@@ -78,76 +86,54 @@ function RegImport {
reg import $path
}
# Change mode based on provided parameters or user input
# Change script mode based on provided parameters or user input
if ((-NOT $PSBoundParameters.Count) -or $RunDefaults -or $RunWin11Defaults -or (($PSBoundParameters.Count -eq 1) -and ($PSBoundParameters.ContainsKey('WhatIf') -or $PSBoundParameters.ContainsKey('Confirm') -or $PSBoundParameters.ContainsKey('Verbose')))) {
if ($RunDefaults -or $RunWin11Defaults) {
$Mode = '1';
}
else {
# Show menu and wait for user input, loops until valid input is provided
Do {
Clear-Host
Write-Output "-------------------------------------------------------------------------------------------"
Write-Output " Win11Debloat Script - Setup"
Write-Output "-------------------------------------------------------------------------------------------"
Write-Output "(1) Run Win11Debloat with the default settings"
Write-Output "(2) Custom mode: Select which changes you want Win11Debloat to make"
Write-Output ""
Write-Output "(0) Show information about the script"
Write-Output ""
Write-Output ""
# Get & print script menu from file
Foreach ($line in (Get-Content -Path "$PSScriptRoot/Menus/Menu.txt" )) {
Write-Output $line
}
$Mode = Read-Host "Please select an option (1/2/0)"
# Show information based on user input
if ($Mode -eq '0') {
Clear-Host
Write-Output "-------------------------------------------------------------------------------------------"
Write-Output " Win11Debloat - Information"
Write-Output "-------------------------------------------------------------------------------------------"
Write-Output "Win11Debloat is a simple and lightweight powershell script that removes pre-installed"
Write-Output "windows bloatware apps, disables telemetry and declutters the experience by disabling"
Write-Output "or removing intrusive interface elements, ads and context menu items. No need to"
Write-Output "painstakingly go through all the settings yourself, or removing apps one by one!"
Write-Output ""
Write-Output "-------------------------------------------------------------------------------------------"
Write-Output " The default settings will"
Write-Output "-------------------------------------------------------------------------------------------"
Write-Output "- Remove bloatware apps, the list can be found in the 'Appslist.txt' file."
Write-Output "- Disable telemetry, diagnostic data & targeted ads."
Write-Output "- Disable bing search & cortana in windows search."
Write-Output "- Disable tips & tricks on the lockscreen. (This may change your lockscreen wallpaper to the default)"
Write-Output "- Disable tips, tricks and suggestions in the start menu and settings, and ads in windows explorer."
Write-Output "- Show file extensions for known file types."
Write-Output "- Disable the widget service & hide the widget (news and interests) icon from the taskbar. "
Write-Output "- Hide the Chat (meet now) icon from the taskbar."
Write-Output "- Hide the 3D objects folder in windows explorer. (Windows 10 only)"
Write-Output ""
Write-Output "-------------------------------------------------------------------------------------------"
Write-Output " The custom mode has more options, in custom mode you can"
Write-Output "-------------------------------------------------------------------------------------------"
Write-Output "- Remove bloatware apps, the list can be found in the 'Appslist.txt' file."
Write-Output "- Remove gaming-related apps, the list can be found in the 'GamingAppslist.txt' file."
Write-Output "- Disable telemetry, diagnostic data & targeted ads."
Write-Output "- Disable bing search & cortana in windows search."
Write-Output "- Disable tips & tricks on the lockscreen. (This may change your lockscreen wallpaper to the default)"
Write-Output "- Disable tips, tricks and suggestions in the start menu and settings, and ads in windows explorer."
Write-Output "- Show hidden files, folders and drives."
Write-Output "- Show file extensions for known file types."
Write-Output "- Align taskbar icons to the left. (Windows 11 only)"
Write-Output "- Hide or change the search icon/box on the taskbar. (Windows 11 only)"
Write-Output "- Disable the widget service & hide the widget (news and interests) icon from the taskbar. "
Write-Output "- Hide the Chat (meet now) icon from the taskbar."
Write-Output "- Hide the 3D objects, music or onedrive folders in windows explorer. (Windows 10 only)"
Write-Output "- Hide the 'Include in library', 'Give access to' and 'Share' options in the context menu. (Windows 10 only)"
Write-Output ""
Write-Output ""
# Get & print script information from file
Foreach ($line in (Get-Content -Path "$PSScriptRoot/Menus/Info.txt" )) {
Write-Output $line
}
Write-Output "Press any key to go back..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
elseif ($Mode -eq '1') {
Clear-Host
# Get & print default settings info from file
Foreach ($line in (Get-Content -Path "$PSScriptRoot/Menus/DefaultSettings.txt" )) {
Write-Output $line
}
Write-Output "Press any key to start..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
}
while ($Mode -ne '1' -and $Mode -ne '2')
}
# Add execution parameters based on the mode
switch ($Mode) {
# Default mode, no user input required, all (relevant) options are added
'1' {
Clear-Host
Write-Output "-------------------------------------------------------------------------------------------"
@@ -162,12 +148,13 @@ if ((-NOT $PSBoundParameters.Count) -or $RunDefaults -or $RunWin11Defaults -or (
$PSBoundParameters.Add('DisableWidgets', $DisableWidgets)
$PSBoundParameters.Add('HideChat', $HideChat)
# Only add option for windows 10 users
# Only add this option for windows 10 users
if (get-ciminstance -query "select caption from win32_operatingsystem where caption like '%Windows 10%'"){
$PSBoundParameters.Add('Hide3dObjects', $Hide3dObjects)
}
}
# Custom mode, add options based on user input
'2' {
Clear-Host
Write-Output "-------------------------------------------------------------------------------------------"
@@ -211,7 +198,7 @@ if ((-NOT $PSBoundParameters.Count) -or $RunDefaults -or $RunWin11Defaults -or (
Write-Output ""
if ($( Read-Host -Prompt "Do you want to make any changes to the taskbar and start menu? (y/n)" ) -eq 'y') {
# Only show option for taskbar alignment for windows 11 users
# Only show these specific options for windows 11 users
if (get-ciminstance -query "select caption from win32_operatingsystem where caption like '%Windows 11%'"){
Write-Output ""
@@ -262,6 +249,8 @@ if ((-NOT $PSBoundParameters.Count) -or $RunDefaults -or $RunWin11Defaults -or (
}
}
Write-Output ""
if ($( Read-Host -Prompt "Do you want to make any changes to windows explorer? (y/n)" ) -eq 'y') {
Write-Output ""
@@ -269,6 +258,8 @@ if ((-NOT $PSBoundParameters.Count) -or $RunDefaults -or $RunWin11Defaults -or (
$PSBoundParameters.Add('ShowHiddenFolders', $ShowHiddenFolders)
}
Write-Output ""
if ($( Read-Host -Prompt " Show file extensions for known file types? (y/n)" ) -eq 'y') {
$PSBoundParameters.Add('ShowKnownFileExt', $ShowKnownFileExt)
}
@@ -335,6 +326,7 @@ else {
Write-Output "-------------------------------------------------------------------------------------------"
}
# Execute all selected/provided parameters
switch ($PSBoundParameters.Keys) {
'RemoveApps' {
@@ -449,6 +441,7 @@ switch ($PSBoundParameters.Keys) {
}
}
Write-Output ""
Write-Output ""
Write-Output "Script completed! Please restart your PC to make sure all changes are properly applied."