From 85491636d6a4c113143d481ec87c056003f6147d Mon Sep 17 00:00:00 2001 From: Andreas Mirbach <6332034+mirbach@users.noreply.github.com> Date: Sun, 9 Aug 2026 17:42:31 +0200 Subject: [PATCH] feat: let admins choose the PowerShell engine for script tasks Adds a dropdown to the PowerShell task form (Windows PowerShell 5.1 / PowerShell 7+ (pwsh) / Auto) reusing the existing script_executable column already used by unix_script tasks. The choice is validated, persisted, and threaded through to wingetcfg.ExecutePowershellScript for both the ad-hoc "run task now" and scheduled profile-application flows. Depends on open-uem/wingetcfg#feat/powershell-7-engine landing and a new wingetcfg version being pinned in go.mod before this builds. --- .../controllers/webserver/handlers/computers.go | 2 +- internal/controllers/webserver/handlers/tasks.go | 6 ++++++ internal/models/tasks.go | 4 ++-- internal/views/locales/ca.yaml | 4 ++++ internal/views/locales/de.yaml | 4 ++++ internal/views/locales/en.yaml | 4 ++++ internal/views/locales/es.yaml | 4 ++++ internal/views/locales/fr.yaml | 4 ++++ internal/views/locales/no.yaml | 4 ++++ internal/views/locales/pt.yaml | 4 ++++ internal/views/partials/powershell.partials.templ | 14 ++++++++++++++ 11 files changed, 51 insertions(+), 3 deletions(-) diff --git a/internal/controllers/webserver/handlers/computers.go b/internal/controllers/webserver/handlers/computers.go index f330231f..6e7274c5 100644 --- a/internal/controllers/webserver/handlers/computers.go +++ b/internal/controllers/webserver/handlers/computers.go @@ -2442,7 +2442,7 @@ func (h *Handler) CreateWindowsTaskConfig(t *openuem_ent.Task) (*wingetcfg.WinGe } cfg.AddResource(msiUninstall) case task.TypePowershellScript: - msiUninstall, err := wingetcfg.ExecutePowershellScript(taskID, t.Name, t.Script, t.ScriptRun.String()) + msiUninstall, err := wingetcfg.ExecutePowershellScript(taskID, t.Name, t.Script, t.ScriptRun.String(), t.ScriptExecutable) if err != nil { return nil, err } diff --git a/internal/controllers/webserver/handlers/tasks.go b/internal/controllers/webserver/handlers/tasks.go index 4540cc96..ec6d379a 100644 --- a/internal/controllers/webserver/handlers/tasks.go +++ b/internal/controllers/webserver/handlers/tasks.go @@ -792,6 +792,12 @@ func validatePowerShellScript(c echo.Context) (*models.TaskConfig, error) { return nil, errors.New(i18n.T(c.Request().Context(), "tasks.shell_wrong_run_config")) } + taskConfig.ShellExecute = c.FormValue("powershell-executable") + validEngines := []string{"", "powershell", "pwsh", "auto"} + if taskType == "powershell_type" && !slices.Contains(validEngines, taskConfig.ShellExecute) { + return nil, errors.New(i18n.T(c.Request().Context(), "tasks.shell_wrong_run_config")) + } + return &taskConfig, nil } diff --git a/internal/models/tasks.go b/internal/models/tasks.go index 186ddc0b..3d18691b 100644 --- a/internal/models/tasks.go +++ b/internal/models/tasks.go @@ -235,7 +235,7 @@ func (m *Model) AddTaskToProfile(c echo.Context, profileID int, cfg TaskConfig) return query.Exec(context.Background()) case task.TypePowershellScript.String(): return query. - SetScript(cfg.ShellScript).SetScriptRun(task.ScriptRun(cfg.ShellRunConfig)).Exec(context.Background()) + SetScript(cfg.ShellScript).SetScriptRun(task.ScriptRun(cfg.ShellRunConfig)).SetScriptExecutable(cfg.ShellExecute).Exec(context.Background()) case task.TypeUnixScript.String(): return query. SetScript(cfg.ShellScript).SetScriptCreates(cfg.ShellCreates).SetScriptExecutable(cfg.ShellExecute).Exec(context.Background()) @@ -391,7 +391,7 @@ func (m *Model) UpdateProfileTask(c echo.Context, taskID int, cfg TaskConfig) er } return query.Exec(context.Background()) case task.TypePowershellScript.String(): - return query.SetScript(cfg.ShellScript).SetScriptRun(task.ScriptRun(cfg.ShellRunConfig)).Exec(context.Background()) + return query.SetScript(cfg.ShellScript).SetScriptRun(task.ScriptRun(cfg.ShellRunConfig)).SetScriptExecutable(cfg.ShellExecute).Exec(context.Background()) case task.TypeUnixScript.String(): return query.SetScript(cfg.ShellScript).SetScriptCreates(cfg.ShellCreates).SetScriptExecutable(cfg.ShellExecute).Exec(context.Background()) case task.TypeFlatpakInstall.String(), task.TypeFlatpakUninstall.String(): diff --git a/internal/views/locales/ca.yaml b/internal/views/locales/ca.yaml index 1031a690..bf3937f6 100644 --- a/internal/views/locales/ca.yaml +++ b/internal/views/locales/ca.yaml @@ -1318,6 +1318,10 @@ ca: shell_run_once: "Executeu només una vegada si té èxit" shell_run_always: "Executeu cada vegada que s'aplica el perfil" shell_wrong_run_config: "La configuració d'execució no és vàlida" + powershell_executable: "Motor de PowerShell" + powershell_engine_51: "Windows PowerShell 5.1" + powershell_engine_7: "PowerShell 7+ (pwsh)" + powershell_engine_auto: "Auto (utilitza PowerShell 7+ si està disponible, si no 5.1)" task_agent: "OS de l'agent" task_agent_description: "Especifiqueu l'agent del sistema operatiu..." wrong_agenttype: "El tipus d'agent no és vàlid" diff --git a/internal/views/locales/de.yaml b/internal/views/locales/de.yaml index beca6f09..58847028 100644 --- a/internal/views/locales/de.yaml +++ b/internal/views/locales/de.yaml @@ -1318,6 +1318,10 @@ de: shell_run_once: "Nur einmal ausführen, wenn erfolgreich" shell_run_always: "Bei jeder Anwendung des Profils ausführen" shell_wrong_run_config: "Ungültige Ausführungskonfiguration" + powershell_executable: "PowerShell-Engine" + powershell_engine_51: "Windows PowerShell 5.1" + powershell_engine_7: "PowerShell 7+ (pwsh)" + powershell_engine_auto: "Auto (PowerShell 7+ verwenden, falls verfügbar, sonst 5.1)" task_agent: "Betriebssystem des Agents" task_agent_description: "Geben Sie das Betriebssystem des Agents an..." wrong_agenttype: "Ungültiger Agent-Typ" diff --git a/internal/views/locales/en.yaml b/internal/views/locales/en.yaml index 5297a06a..284dfeca 100644 --- a/internal/views/locales/en.yaml +++ b/internal/views/locales/en.yaml @@ -1318,6 +1318,10 @@ en: shell_run_once: "Run only once if successful" shell_run_always: "Run every time the profile is applied" shell_wrong_run_config: "Run configuration is not valid" + powershell_executable: "PowerShell engine" + powershell_engine_51: "Windows PowerShell 5.1" + powershell_engine_7: "PowerShell 7+ (pwsh)" + powershell_engine_auto: "Auto (use PowerShell 7+ if available, otherwise 5.1)" task_agent: "Agent's OS" task_agent_description: "Specify the OS agent..." wrong_agenttype: "Agent's type is not valid" diff --git a/internal/views/locales/es.yaml b/internal/views/locales/es.yaml index 58bce461..e345e1e0 100644 --- a/internal/views/locales/es.yaml +++ b/internal/views/locales/es.yaml @@ -1318,6 +1318,10 @@ es: shell_run_once: "Ejecutar solo una vez si tiene éxito" shell_run_always: "Ejecutar cada vez que se aplique el perfil" shell_wrong_run_config: "La configuración de ejecución no es válida" + powershell_executable: "Motor de PowerShell" + powershell_engine_51: "Windows PowerShell 5.1" + powershell_engine_7: "PowerShell 7+ (pwsh)" + powershell_engine_auto: "Auto (usar PowerShell 7+ si está disponible, si no 5.1)" task_agent: "S.O del agente" task_agent_description: "Especifique el S.O del agente..." wrong_agenttype: "El tipo de agente no es válido" diff --git a/internal/views/locales/fr.yaml b/internal/views/locales/fr.yaml index 1b6f55fa..402a0782 100644 --- a/internal/views/locales/fr.yaml +++ b/internal/views/locales/fr.yaml @@ -1318,6 +1318,10 @@ fr: shell_run_once: "Exécuter une seule fois si réussi" shell_run_always: "Exécuter chaque fois que le profil est appliqué" shell_wrong_run_config: "La configuration d'exécution n'est pas valide" + powershell_executable: "Moteur PowerShell" + powershell_engine_51: "Windows PowerShell 5.1" + powershell_engine_7: "PowerShell 7+ (pwsh)" + powershell_engine_auto: "Auto (utiliser PowerShell 7+ si disponible, sinon 5.1)" task_agent: "Système d'exploitation de l'agent" task_agent_description: "Spécifier l'agent du système d'exploitation..." wrong_agenttype: "Le type d'agent n'est pas valide" diff --git a/internal/views/locales/no.yaml b/internal/views/locales/no.yaml index fc6def1f..ced78844 100644 --- a/internal/views/locales/no.yaml +++ b/internal/views/locales/no.yaml @@ -1318,6 +1318,10 @@ no: shell_run_once: "Kjør bare én gang hvis vellykket" shell_run_always: "Kjør hver gang profilen brukes" shell_wrong_run_config: "Kjøringskonfigurasjon er ikke gyldig" + powershell_executable: "PowerShell-motor" + powershell_engine_51: "Windows PowerShell 5.1" + powershell_engine_7: "PowerShell 7+ (pwsh)" + powershell_engine_auto: "Auto (bruk PowerShell 7+ hvis tilgjengelig, ellers 5.1)" task_agent: "Agentens OS" task_agent_description: "Spesifiser OS-agenten..." wrong_agenttype: "Agenttype er ikke gyldig" diff --git a/internal/views/locales/pt.yaml b/internal/views/locales/pt.yaml index c220172d..cb777bb8 100644 --- a/internal/views/locales/pt.yaml +++ b/internal/views/locales/pt.yaml @@ -1318,6 +1318,10 @@ pt: shell_run_once: "Executar apenas uma vez se bem-sucedido" shell_run_always: "Executar toda vez que o perfil for aplicado" shell_wrong_run_config: "Configuração de execução não é válida" + powershell_executable: "Motor do PowerShell" + powershell_engine_51: "Windows PowerShell 5.1" + powershell_engine_7: "PowerShell 7+ (pwsh)" + powershell_engine_auto: "Auto (usar PowerShell 7+ se disponível, senão 5.1)" task_agent: "SO do Agente" task_agent_description: "Especifique o agente do SO..." wrong_agenttype: "Tipo de agente não é válido" diff --git a/internal/views/partials/powershell.partials.templ b/internal/views/partials/powershell.partials.templ index 5c20d081..cc1b1424 100644 --- a/internal/views/partials/powershell.partials.templ +++ b/internal/views/partials/powershell.partials.templ @@ -41,5 +41,19 @@ templ PowerShellComponent(t *ent.Task) { +
+ + +
}