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
|
|
|
|
)
|
|
|
|
|
2024-07-25 16:19:45 -05:00
|
|
|
$x = 0
|
|
|
|
|
2023-05-09 13:14:27 -05:00
|
|
|
$CheckBox | ForEach-Object {
|
2024-08-06 15:35:17 -05:00
|
|
|
if($sync.configs.feature.$psitem.feature) {
|
|
|
|
Foreach( $feature in $sync.configs.feature.$psitem.feature ) {
|
|
|
|
try {
|
2023-05-09 13:14:27 -05:00
|
|
|
Write-Host "Installing $feature"
|
|
|
|
Enable-WindowsOptionalFeature -Online -FeatureName $feature -All -NoRestart
|
2024-08-06 15:35:17 -05:00
|
|
|
} catch {
|
|
|
|
if ($psitem.Exception.Message -like "*requires elevation*") {
|
2023-05-09 13:14:27 -05:00
|
|
|
Write-Warning "Unable to Install $feature due to permissions. Are you running as admin?"
|
2024-07-25 16:19:45 -05:00
|
|
|
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" })
|
2024-08-06 15:35:17 -05:00
|
|
|
} else {
|
2024-07-25 16:19:45 -05:00
|
|
|
|
2023-05-09 13:14:27 -05:00
|
|
|
Write-Warning "Unable to Install $feature due to unhandled exception"
|
2023-10-19 17:12:55 -05:00
|
|
|
Write-Warning $psitem.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
|
|
|
}
|
2024-08-06 15:35:17 -05:00
|
|
|
if($sync.configs.feature.$psitem.InvokeScript) {
|
|
|
|
Foreach( $script in $sync.configs.feature.$psitem.InvokeScript ) {
|
|
|
|
try {
|
2023-05-09 13:14:27 -05:00
|
|
|
$Scriptblock = [scriptblock]::Create($script)
|
|
|
|
|
|
|
|
Write-Host "Running Script for $psitem"
|
|
|
|
Invoke-Command $scriptblock -ErrorAction stop
|
2024-08-06 15:35:17 -05:00
|
|
|
} catch {
|
|
|
|
if ($psitem.Exception.Message -like "*requires elevation*") {
|
2023-05-09 13:14:27 -05:00
|
|
|
Write-Warning "Unable to Install $feature due to permissions. Are you running as admin?"
|
2024-07-25 16:19:45 -05:00
|
|
|
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" })
|
2024-08-06 15:35:17 -05:00
|
|
|
} else {
|
2024-07-25 16:19:45 -05:00
|
|
|
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" })
|
2023-05-09 13:14:27 -05:00
|
|
|
Write-Warning "Unable to Install $feature due to unhandled exception"
|
2023-10-19 17:12:55 -05:00
|
|
|
Write-Warning $psitem.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
|
|
|
}
|
2024-07-25 16:19:45 -05:00
|
|
|
$X++
|
|
|
|
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -value ($x/$CheckBox.Count) })
|
2023-05-09 13:14:27 -05:00
|
|
|
}
|
|
|
|
}
|