2023-05-09 13:14:27 -05:00
|
|
|
function Invoke-WinUtilFeatureInstall {
|
|
|
|
|
<#
|
2023-10-19 17:12:55 -05:00
|
|
|
|
|
|
|
|
.SYNOPSIS
|
|
|
|
|
Converts all the values from the tweaks.json and routes them to the appropriate function
|
|
|
|
|
|
2023-05-09 13:14:27 -05:00
|
|
|
#>
|
|
|
|
|
|
|
|
|
|
param(
|
|
|
|
|
$CheckBox
|
|
|
|
|
)
|
|
|
|
|
|
2026-02-22 17:28:55 -06:00
|
|
|
if($sync.configs.feature.$CheckBox.feature) {
|
|
|
|
|
Foreach( $feature in $sync.configs.feature.$CheckBox.feature ) {
|
|
|
|
|
try {
|
|
|
|
|
Write-Host "Installing $feature"
|
|
|
|
|
Enable-WindowsOptionalFeature -Online -FeatureName $feature -All -NoRestart
|
|
|
|
|
} catch {
|
|
|
|
|
if ($CheckBox.Exception.Message -like "*requires elevation*") {
|
|
|
|
|
Write-Warning "Unable to Install $feature due to permissions. Are you running as admin?"
|
|
|
|
|
Invoke-WPFUIThread -ScriptBlock { Set-WinUtilTaskbaritem -state "Error" }
|
|
|
|
|
} else {
|
2024-07-25 23:19:45 +02:00
|
|
|
|
2026-03-26 21:26:21 +01:00
|
|
|
Write-Warning "Unable to Install $feature due to unhandled exception."
|
2026-02-22 17:28:55 -06:00
|
|
|
Write-Warning $CheckBox.Exception.StackTrace
|
2023-05-09 13:14:27 -05:00
|
|
|
}
|
2023-10-19 17:12:55 -05:00
|
|
|
}
|
2023-05-09 13:14:27 -05:00
|
|
|
}
|
2026-02-22 17:28:55 -06:00
|
|
|
}
|
|
|
|
|
if($sync.configs.feature.$CheckBox.InvokeScript) {
|
|
|
|
|
Foreach( $script in $sync.configs.feature.$CheckBox.InvokeScript ) {
|
|
|
|
|
try {
|
|
|
|
|
$Scriptblock = [scriptblock]::Create($script)
|
2023-05-09 13:14:27 -05:00
|
|
|
|
2026-02-22 17:28:55 -06:00
|
|
|
Write-Host "Running Script for $CheckBox"
|
|
|
|
|
Invoke-Command $scriptblock -ErrorAction stop
|
|
|
|
|
} catch {
|
|
|
|
|
if ($CheckBox.Exception.Message -like "*requires elevation*") {
|
|
|
|
|
Write-Warning "Unable to Install $feature due to permissions. Are you running as admin?"
|
|
|
|
|
Invoke-WPFUIThread -ScriptBlock { Set-WinUtilTaskbaritem -state "Error" }
|
|
|
|
|
} else {
|
|
|
|
|
Invoke-WPFUIThread -ScriptBlock { Set-WinUtilTaskbaritem -state "Error" }
|
2026-03-26 21:26:21 +01:00
|
|
|
Write-Warning "Unable to Install $feature due to unhandled exception."
|
2026-02-22 17:28:55 -06:00
|
|
|
Write-Warning $CheckBox.Exception.StackTrace
|
2023-05-09 13:14:27 -05:00
|
|
|
}
|
2023-10-19 17:12:55 -05:00
|
|
|
}
|
2023-05-09 13:14:27 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|