Files
winutil/functions/private/Invoke-WinUtilFeatureInstall.ps1
2026-03-05 17:20:30 -06:00

64 lines
2.7 KiB
PowerShell

function Invoke-WinUtilFeatureInstall {
<#
.SYNOPSIS
Converts all the values from the tweaks.json and routes them to the appropriate function
#>
param(
$CheckBox
)
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 ($_.Exception -and $_.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 {
Write-Warning "Unable to Install $feature due to unhandled exception"
if ($_.Exception) {
if (-not [string]::IsNullOrWhiteSpace($_.Exception.Message)) {
Write-Warning $_.Exception.Message
}
if (-not [string]::IsNullOrWhiteSpace($_.Exception.StackTrace)) {
Write-Warning $_.Exception.StackTrace
}
}
}
}
}
}
if($sync.configs.feature.$CheckBox.InvokeScript) {
Foreach( $script in $sync.configs.feature.$CheckBox.InvokeScript ) {
try {
$Scriptblock = [scriptblock]::Create($script)
Write-Host "Running Script for $CheckBox"
Invoke-Command $scriptblock -ErrorAction stop
} catch {
if ($_.Exception -and $_.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" }
Write-Warning "Unable to Install $feature due to unhandled exception"
if ($_.Exception) {
if (-not [string]::IsNullOrWhiteSpace($_.Exception.Message)) {
Write-Warning $_.Exception.Message
}
if (-not [string]::IsNullOrWhiteSpace($_.Exception.StackTrace)) {
Write-Warning $_.Exception.StackTrace
}
}
}
}
}
}
}