Files
winutil/functions/private/Invoke-WinUtilFeatureInstall.ps1
T

56 lines
2.2 KiB
PowerShell
Raw Normal View History

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