Added new parameter to suppress all prompts during runtime (#8)

This commit is contained in:
Raphire
2023-09-27 21:03:25 +02:00
parent 14246951fa
commit 1b6ce050ab
2 changed files with 28 additions and 12 deletions

View File

@@ -56,7 +56,7 @@ Disclaimer: I believe this script to be completely safe to run, in fact, great c
### Advanced method
This method gives you the option to run the script with certain parameters to tailor the behaviour of the script to your needs without requiring any user input during runtime, making it quicker and easier to deploy on a large number of systems.
This method gives you the option to run the script with certain parameters to tailor the behaviour of the script to your needs and it allows you to run the script without requiring any user input during runtime, making it quicker and easier to deploy on a large number of systems.
1. [Download the latest version of the script](https://github.com/Raphire/Win11Debloat/archive/master.zip), and extract the .ZIP file to your desired location.
2. Open powershell as an administrator.
@@ -65,10 +65,11 @@ This method gives you the option to run the script with certain parameters to ta
5. Enter this into powershell to run the script: `.\Win11Debloat.ps1`
6. A menu will now open. Select either the default or custom setup to continue.
To run the script without any user input, simply add parameters at the end, example: `.\Win11Debloat.ps1 -RemoveApps -DisableBing`
To run the script without any user input, simply add parameters at the end, example: `.\Win11Debloat.ps1 -RemoveApps -DisableBing -Silent`
| Parameter | Description |
| --------- | ----------- |
| -Silent | Suppresses all interactive prompts, so the script will run without requiring any user input. |
| -RunDefaults | Run the script with the default settings. |
| -RemoveApps | Remove all bloatware apps from [this list](#click-for-list-of-bloat-that-is-removed). |
| -RemoveGamingApps | Remove the Xbox App and Xbox Gamebar. |

View File

@@ -3,6 +3,7 @@
[CmdletBinding(SupportsShouldProcess)]
param
(
[Parameter(ValueFromPipeline = $true)][switch]$Silent,
[Parameter(ValueFromPipeline = $true)][switch]$RunDefaults,
[Parameter(ValueFromPipeline = $true)][switch]$RunWin11Defaults,
[Parameter(ValueFromPipeline = $true)][switch]$RemoveApps,
@@ -144,7 +145,7 @@ function ClearStartMenu {
$defaultProfile = "C:\Users\default\AppData\Local\Packages\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\LocalState"
# Create folder if it doesn't exist
if(-not(Test-Path $defaultProfile)) {
if(-Not(Test-Path $defaultProfile)) {
new-item $defaultProfile -ItemType Directory -Force | Out-Null
Write-Output "Created LocalState folder for default user"
}
@@ -155,8 +156,17 @@ function ClearStartMenu {
}
$SPParams = 'WhatIf', 'Confirm', 'Verbose'
$SPParamCount = 0
foreach ($param in $SPParams) {
if ($PSBoundParameters.ContainsKey($param)) {
$SPParamCount++
}
}
# Change script execution 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 ((-Not $PSBoundParameters.Count) -or $RunDefaults -or $RunWin11Defaults -or ($SPParamCount -eq $PSBoundParameters.Count)) {
if ($RunDefaults -or $RunWin11Defaults) {
$Mode = '1';
}
@@ -253,7 +263,7 @@ if ((-NOT $PSBoundParameters.Count) -or $RunDefaults -or $RunWin11Defaults -or (
Write-Output ""
if ($( Read-Host -Prompt "Disable tips, tricks, suggestions and ads in start, settings, notifications, windows explorer and on the lockscreen? (y/n)" ) -eq 'y') {
if ($( Read-Host -Prompt "Disable tips, tricks, suggestions and ads in start, settings, notifications, explorer and lockscreen? (y/n)" ) -eq 'y') {
$PSBoundParameters.Add('DisableSuggestions', $DisableSuggestions)
$PSBoundParameters.Add('DisableLockscreenTips', $DisableLockscreenTips)
}
@@ -262,7 +272,7 @@ if ((-NOT $PSBoundParameters.Count) -or $RunDefaults -or $RunWin11Defaults -or (
# Only show this option for windows 11 users
if (get-ciminstance -query "select caption from win32_operatingsystem where caption like '%Windows 11%'"){
if ($( Read-Host -Prompt "Remove all pinned apps from the start menu? This applies to all existing and new users (y/n)" ) -eq 'y') {
if ($( Read-Host -Prompt "Remove all pinned apps from the start menu? This applies to all existing and new users and can't be reverted (y/n)" ) -eq 'y') {
$PSBoundParameters.Add('ClearStart', $ClearStart)
}
}
@@ -404,6 +414,7 @@ if ((-NOT $PSBoundParameters.Count) -or $RunDefaults -or $RunWin11Defaults -or (
Write-Output ""
Write-Output "Press any key to confirm your choices and execute the script..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Clear-Host
Write-Output "-------------------------------------------------------------------------------------------"
Write-Output " Win11Debloat Script - Custom Configuration"
@@ -447,7 +458,7 @@ switch ($PSBoundParameters.Keys) {
continue
}
{$_ -in "DisableSuggestions", "DisableWindowsSuggestions"} {
RegImport "> Disabling tips, tricks, suggestions and ads in start, settings, notifications and windows explorer..." $PSScriptRoot\Regfiles\Disable_Windows_Suggestions.reg
RegImport "> Disabling tips, tricks, suggestions and ads across Windows..." $PSScriptRoot\Regfiles\Disable_Windows_Suggestions.reg
Write-Output ""
continue
}
@@ -547,8 +558,12 @@ RestartExplorer
Write-Output ""
Write-Output ""
Write-Output "Script completed!"
Write-Output ""
Write-Output ""
Write-Output "Press any key to continue..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Write-Output "Script completed successfully!"
# Suppress prompt if Silent parameter was passed
if(-Not $Silent) {
Write-Output ""
Write-Output "Press any key to exit..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}