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..."