Refactor feature toggling logic in

DISM-FEATURES.ps1
This commit is contained in:
h3r0 2023-11-19 19:31:45 +00:00 committed by GitHub
parent 34f3b09d02
commit 6c281ffa1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 10 deletions

View File

@ -9,17 +9,13 @@ function Toggle-Feature {
$dismCmd = if ($bool) { "Enable" } else { "Disable" }
if ($regKey -eq $null) {
if ($regKey -eq $null -or ($regKey.Selection -eq 0 -and $bool) -or ($regKey.Selection -eq 1 -and !$bool)) {
Write-Host "$dismCmd $featureName"
} else {
if (($regKey.Selection -eq 0 -and $bool) -or ($regKey.Selection -eq 1 -and !$bool)) {
Write-Host "$dismCmd $featureName"
if ($bool) {
Enable-WindowsOptionalFeature -Online -FeatureName $featureName -NoRestart
} else {
Disable-WindowsOptionalFeature -Online -FeatureName $featureName -NoRestart
}
}
if ($bool) {
Enable-WindowsOptionalFeature -Online -FeatureName $featureName -NoRestart
} else {
Disable-WindowsOptionalFeature -Online -FeatureName $featureName -NoRestart
}
}
}