refactor - use PowerShell cmdlets instead of DISM

This commit is contained in:
h3r0 2023-11-07 15:39:12 +00:00 committed by GitHub
parent a1fc44e17d
commit 0a8692abb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 4 deletions

View File

@ -7,16 +7,18 @@ function Toggle-Feature {
$regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Notifications\OptionalFeatures"
$regKey = Get-ItemProperty -Path "$regPath\$featureName" -ErrorAction SilentlyContinue
$dismCmd = if ($bool) { "Enable-Feature" } else { "Disable-Feature" }
$dismCmd = if ($bool) { "Enable" } else { "Disable" }
if ($regKey -eq $null) {
Write-Host "$dismCmd $featureName"
DISM /Online /$dismCmd /FeatureName:"$featureName" /NoRestart
} else {
if (($regKey.Selection -eq 0 -and $bool) -or ($regKey.Selection -eq 1 -and !$bool)) {
Write-Host "$dismCmd $featureName"
DISM /Online /$dismCmd /FeatureName:"$featureName" /NoRestart
if ($bool) {
Enable-WindowsOptionalFeature -Online -FeatureName $featureName -NoRestart
} else {
Disable-WindowsOptionalFeature -Online -FeatureName $featureName -NoRestart
}
}
}
}