Improve Windows feature enabling

This commit is contained in:
Raphire
2026-02-18 19:07:21 +01:00
parent 2c940ff489
commit c76c3ce7ac

View File

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