forked from LeDragoX/Win-Debloat-Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor
: add lib to uninstall/install optional features
- Optimized code from optimize-windows-features - There are to switches to the function: `-Disabled` or `-Enabled` - Also disable Internet Explorer from Optional Features
- Loading branch information
Showing
2 changed files
with
100 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
Import-Module -DisableNameChecking $PSScriptRoot\..\lib\"title-templates.psm1" | ||
|
||
function Find-OptionalFeature() { | ||
[CmdletBinding()] | ||
[OutputType([Bool])] | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
[String] $OptionalFeature | ||
) | ||
|
||
If (Get-WindowsOptionalFeature -Online -FeatureName $OptionalFeature) { | ||
return $true | ||
} | ||
Else { | ||
Write-Status -Symbol "?" -Type $TweakType -Status "The $OptionalFeature optional feature was not found." -Warning | ||
return $false | ||
} | ||
} | ||
|
||
function Set-OptionalFeatureState() { | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(Mandatory = $false)] | ||
[Switch] $Disabled, | ||
[Parameter(Mandatory = $false)] | ||
[Switch] $Enabled, | ||
[Parameter(Mandatory = $true)] | ||
[Array] $OptionalFeatures, | ||
[Parameter(Mandatory = $false)] | ||
[Array] $Filter, | ||
[Parameter(Mandatory = $false)] | ||
[ScriptBlock] $CustomMessage | ||
) | ||
|
||
$Script:SecurityFilterOnEnable = @("IIS-*") | ||
$Script:TweakType = "OptionalFeature" | ||
|
||
ForEach ($OptionalFeature in $OptionalFeatures) { | ||
If (Find-OptionalFeature $OptionalFeature) { | ||
If (($OptionalFeature -in $SecurityFilterOnEnable) -and ($Enabled)) { | ||
Write-Status -Symbol "?" -Type $TweakType -Status "Skipping $OptionalFeature to avoid a security vulnerability ..." -Warning | ||
Continue | ||
} | ||
|
||
If ($OptionalFeature -in $Filter) { | ||
Write-Status -Symbol "?" -Type $TweakType -Status "The $OptionalFeature will be skipped as set on Filter ..." -Warning | ||
Continue | ||
} | ||
|
||
If (!$CustomMessage) { | ||
If ($Disabled) { | ||
Write-Status -Symbol "-" -Type $TweakType -Status "Uninstalling the $OptionalFeature optional feature ..." | ||
} | ||
ElseIf ($Enabled) { | ||
Write-Status -Symbol "+" -Type $TweakType -Status "Installing the $OptionalFeature optional feature ..." | ||
} | ||
Else { | ||
Write-Status -Symbol "?" -Type $TweakType -Status "No parameter received (valid params: -Disabled or -Enabled)" -Warning | ||
} | ||
} | ||
Else { | ||
Write-Status -Symbol "@" -Type $TweakType -Status $(Invoke-Expression "$CustomMessage") | ||
} | ||
|
||
If ($Disabled) { | ||
Get-WindowsOptionalFeature -Online -FeatureName $OptionalFeature | Where-Object State -Like "Enabled" | Disable-WindowsOptionalFeature -Online -NoRestart | ||
} | ||
ElseIf ($Enabled) { | ||
Get-WindowsOptionalFeature -Online -FeatureName $OptionalFeature | Where-Object State -Like "Disabled*" | Enable-WindowsOptionalFeature -Online -NoRestart | ||
} | ||
} | ||
} | ||
} | ||
|
||
<# | ||
Set-OptionalFeatureState -Disabled -OptionalFeatures @("OptionalFeature1", "OptionalFeature2", "OptionalFeature3") | ||
Set-OptionalFeatureState -Disabled -OptionalFeatures @("OptionalFeature1", "OptionalFeature2", "OptionalFeature3") -Filter @("OptionalFeature3") | ||
Set-OptionalFeatureState -Disabled -OptionalFeatures @("OptionalFeature1", "OptionalFeature2", "OptionalFeature3") -Filter @("OptionalFeature3") -CustomMessage { "Uninstalling $OptionalFeature feature!"} | ||
Set-OptionalFeatureState -Enabled -OptionalFeatures @("OptionalFeature1", "OptionalFeature2", "OptionalFeature3") | ||
Set-OptionalFeatureState -Enabled -OptionalFeatures @("OptionalFeature1", "OptionalFeature2", "OptionalFeature3") -Filter @("OptionalFeature3") | ||
Set-OptionalFeatureState -Enabled -OptionalFeatures @("OptionalFeature1", "OptionalFeature2", "OptionalFeature3") -Filter @("OptionalFeature3") -CustomMessage { "Installing $OptionalFeature feature!"} | ||
#> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters