From c76c3ce7acacc8704d435f1867bccdffbd8ffe11 Mon Sep 17 00:00:00 2001 From: Raphire <9938813+Raphire@users.noreply.github.com> Date: Wed, 18 Feb 2026 19:07:21 +0100 Subject: [PATCH] Improve Windows feature enabling --- Win11Debloat.ps1 | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Win11Debloat.ps1 b/Win11Debloat.ps1 index 20d5d48..f8c2eb2 100755 --- a/Win11Debloat.ps1 +++ b/Win11Debloat.ps1 @@ -882,14 +882,14 @@ function ExecuteParameter { } "EnableWindowsSandbox" { Write-ToConsole "> Enabling Windows Sandbox..." - Enable-WindowsOptionalFeature -Online -FeatureName "Containers-DisposableClientVM" -All -NoRestart + EnableWindowsFeature "Containers-DisposableClientVM" Write-ToConsole "" return } "EnableWindowsSubsystemForLinux" { Write-ToConsole "> Enabling Windows Subsystem for Linux..." - Enable-WindowsOptionalFeature -Online -FeatureName "VirtualMachinePlatform" -All -NoRestart - Enable-WindowsOptionalFeature -Online -FeatureName "Microsoft-Windows-Subsystem-Linux" -All -NoRestart + EnableWindowsFeature "VirtualMachinePlatform" + EnableWindowsFeature "Microsoft-Windows-Subsystem-Linux" Write-ToConsole "" return } @@ -1048,6 +1048,18 @@ function CreateSystemRestorePoint { } +# Enables a Windows optional feature and pipes its output to Write-ToConsole +function EnableWindowsFeature { + param ( + [string]$FeatureName + ) + + Enable-WindowsOptionalFeature -Online -FeatureName $FeatureName -All -NoRestart *>&1 ` + | Where-Object { $_ -isnot [Microsoft.Dism.Commands.ImageObject] -and $_.ToString() -notlike '*Restart is suppressed*' } ` + | ForEach-Object { $msg = $_.ToString().Trim(); if ($msg) { Write-ToConsole $msg } } +} + + # Restart the Windows Explorer process function RestartExplorer { Write-ToConsole "> Attempting to restart the Windows Explorer process to apply all changes..."