Running script with -Verbose parameter now shows app uninstall progress bars

Linting
This commit is contained in:
Raphire
2024-08-17 00:08:09 +02:00
parent 60f944d116
commit 7cd8f063c7
2 changed files with 21 additions and 13 deletions

View File

@@ -1,5 +1,6 @@
param ( param (
[switch]$Silent, [switch]$Silent,
[switch]$Verbose,
[switch]$Sysprep, [switch]$Sysprep,
[switch]$RunAppConfigurator, [switch]$RunAppConfigurator,
[switch]$RunDefaults, [switch]$RunWin11Defaults, [switch]$RunDefaults, [switch]$RunWin11Defaults,
@@ -59,7 +60,7 @@ Write-Output "> Downloading Win11Debloat..."
Invoke-WebRequest http://github.com/raphire/win11debloat/archive/master.zip -OutFile "$env:TEMP/win11debloat-temp.zip" Invoke-WebRequest http://github.com/raphire/win11debloat/archive/master.zip -OutFile "$env:TEMP/win11debloat-temp.zip"
# Remove old script folder if it exists # Remove old script folder if it exists
if(Test-Path "$env:TEMP/Win11Debloat") { if (Test-Path "$env:TEMP/Win11Debloat") {
Write-Output "" Write-Output ""
Write-Output "> Cleaning up old Win11Debloat folder..." Write-Output "> Cleaning up old Win11Debloat folder..."
Remove-Item -LiteralPath "$env:TEMP/Win11Debloat" -Force -Recurse Remove-Item -LiteralPath "$env:TEMP/Win11Debloat" -Force -Recurse
@@ -84,7 +85,7 @@ Write-Output "> Running Win11Debloat..."
$debloatProcess = Start-Process powershell.exe -PassThru -ArgumentList "-executionpolicy bypass -File $env:TEMP\Win11Debloat\Win11Debloat-master\Win11Debloat.ps1 $arguments" -Verb RunAs $debloatProcess = Start-Process powershell.exe -PassThru -ArgumentList "-executionpolicy bypass -File $env:TEMP\Win11Debloat\Win11Debloat-master\Win11Debloat.ps1 $arguments" -Verb RunAs
# Wait for the process to finish before continuing # Wait for the process to finish before continuing
if($debloatProcess -ne $null) { if ($null -ne $debloatProcess) {
$debloatProcess.WaitForExit() $debloatProcess.WaitForExit()
} }

View File

@@ -100,23 +100,23 @@ function ShowAppSelectionForm {
$selectionBox_MouseDown= $selectionBox_MouseDown=
{ {
if ($_.Button -eq [System.Windows.Forms.MouseButtons]::Left) { if ($_.Button -eq [System.Windows.Forms.MouseButtons]::Left) {
if([System.Windows.Forms.Control]::ModifierKeys -eq [System.Windows.Forms.Keys]::Shift) { if ([System.Windows.Forms.Control]::ModifierKeys -eq [System.Windows.Forms.Keys]::Shift) {
if($global:selectionBoxIndex -ne -1) { if ($global:selectionBoxIndex -ne -1) {
$topIndex = $global:selectionBoxIndex $topIndex = $global:selectionBoxIndex
if ($selectionBox.SelectedIndex -gt $topIndex) { if ($selectionBox.SelectedIndex -gt $topIndex) {
for(($i = ($topIndex)); $i -le $selectionBox.SelectedIndex; $i++){ for (($i = ($topIndex)); $i -le $selectionBox.SelectedIndex; $i++){
$selectionBox.SetItemChecked($i, $selectionBox.GetItemChecked($topIndex)) $selectionBox.SetItemChecked($i, $selectionBox.GetItemChecked($topIndex))
} }
} }
elseif ($topIndex -gt $selectionBox.SelectedIndex) { elseif ($topIndex -gt $selectionBox.SelectedIndex) {
for(($i = ($selectionBox.SelectedIndex)); $i -le $topIndex; $i++){ for (($i = ($selectionBox.SelectedIndex)); $i -le $topIndex; $i++){
$selectionBox.SetItemChecked($i, $selectionBox.GetItemChecked($topIndex)) $selectionBox.SetItemChecked($i, $selectionBox.GetItemChecked($topIndex))
} }
} }
} }
} }
elseif($global:selectionBoxIndex -ne $selectionBox.SelectedIndex) { elseif ($global:selectionBoxIndex -ne $selectionBox.SelectedIndex) {
$selectionBox.SetItemChecked($selectionBox.SelectedIndex, -not $selectionBox.GetItemChecked($selectionBox.SelectedIndex)) $selectionBox.SetItemChecked($selectionBox.SelectedIndex, -not $selectionBox.GetItemChecked($selectionBox.SelectedIndex))
} }
} }
@@ -124,7 +124,7 @@ function ShowAppSelectionForm {
$check_All= $check_All=
{ {
for(($i = 0); $i -lt $selectionBox.Items.Count; $i++){ for (($i = 0); $i -lt $selectionBox.Items.Count; $i++){
$selectionBox.SetItemChecked($i, $checkUncheckCheckBox.Checked) $selectionBox.SetItemChecked($i, $checkUncheckCheckBox.Checked)
} }
} }
@@ -391,7 +391,7 @@ function ForceRemoveEdge {
# Remove edge # Remove edge
$uninstallRegKey = $hklm.OpenSubKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Edge') $uninstallRegKey = $hklm.OpenSubKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Edge')
if($uninstallRegKey -ne $null) { if ($null -ne $uninstallRegKey) {
Write-Output "Running uninstaller..." Write-Output "Running uninstaller..."
$uninstallString = $uninstallRegKey.GetValue('UninstallString') + ' --force-uninstall' $uninstallString = $uninstallRegKey.GetValue('UninstallString') + ' --force-uninstall'
Start-Process cmd.exe "/c $uninstallString" -WindowStyle Hidden -Wait Start-Process cmd.exe "/c $uninstallString" -WindowStyle Hidden -Wait
@@ -513,6 +513,7 @@ function ReplaceStartMenuForAllUsers {
# Check if template bin file exists, return early if it doesn't # Check if template bin file exists, return early if it doesn't
if (-not (Test-Path $startMenuTemplate)) { if (-not (Test-Path $startMenuTemplate)) {
Write-Host "Error: Unable to clear start menu, start2.bin file missing from script folder" -ForegroundColor Red Write-Host "Error: Unable to clear start menu, start2.bin file missing from script folder" -ForegroundColor Red
Write-Output ""
return return
} }
@@ -609,7 +610,7 @@ function PrintHeader {
$fullTitle = " Win11Debloat Script - $title" $fullTitle = " Win11Debloat Script - $title"
if($global:Params.ContainsKey("Sysprep")) { if ($global:Params.ContainsKey("Sysprep")) {
$fullTitle = "$fullTitle (Sysprep mode)" $fullTitle = "$fullTitle (Sysprep mode)"
} }
else { else {
@@ -675,9 +676,6 @@ else {
# Get current Windows build version to compare against features # Get current Windows build version to compare against features
$WinVersion = Get-ItemPropertyValue 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' CurrentBuild $WinVersion = Get-ItemPropertyValue 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' CurrentBuild
# Hide progress bars for app removal, as they block Win11Debloat's output
$ProgressPreference = 'SilentlyContinue'
$global:Params = $PSBoundParameters $global:Params = $PSBoundParameters
$global:FirstSelection = $true $global:FirstSelection = $true
$SPParams = 'WhatIf', 'Confirm', 'Verbose', 'Silent', 'Sysprep' $SPParams = 'WhatIf', 'Confirm', 'Verbose', 'Silent', 'Sysprep'
@@ -691,6 +689,15 @@ foreach ($Param in $SPParams) {
} }
} }
# Hide progress bars for app removal, as they block Win11Debloat's output
if (-not ($global:Params.ContainsKey("Verbose"))) {
$ProgressPreference = 'SilentlyContinue'
}
else {
Read-Host "Verbose mode is enabled, press enter to continue"
$ProgressPreference = 'Continue'
}
if ($global:Params.ContainsKey("Sysprep")) { if ($global:Params.ContainsKey("Sysprep")) {
# Exit script if default user directory or NTUSER.DAT file cannot be found # Exit script if default user directory or NTUSER.DAT file cannot be found
if (-not (Test-Path "C:\Users\Default\NTUSER.DAT")) { if (-not (Test-Path "C:\Users\Default\NTUSER.DAT")) {