JosefNemec/Playnite · error · Exception

LOC.ErrorPowerShellNotInstalled

Error message

LOC.ErrorPowerShellNotInstalled

What it means

Thrown by MainViewModelBase.RunAppScript when PowerShellRuntime.IsInstalled is false before attempting to execute a user-configured application event script (startup/shutdown etc.). The message is the localized LOC.ErrorPowerShellNotInstalled string so the user sees a clear 'PowerShell is not installed' dialog. The surrounding try/catch (!PlayniteEnvironment.ThrowAllErrors) catches it and shows a message box.

Source

Thrown at source/Playnite/ViewModels/MainViewModelBase.cs:849

            await GlobalTaskHandler.CancelAndWaitAsync();
        }

        public virtual void SelectGame(Guid id, bool restoreView = false)
        {
        }

        private void RunAppScript(string script, string eventName)
        {
            if (script.IsNullOrWhiteSpace())
            {
                return;
            }

            try
            {
                if (!PowerShellRuntime.IsInstalled)
                {
                    throw new Exception(ResourceProvider.GetString(LOC.ErrorPowerShellNotInstalled));
                }

                using (var runtime = new PowerShellRuntime($"app {eventName} script"))
                {
                    runtime.Execute(
                        script,
                        PlaynitePaths.ProgramPath,
                        new Dictionary<string, object> { { "PlayniteApi", App.PlayniteApiGlobal } });
                }
            }
            catch (Exception exc) when (!PlayniteEnvironment.ThrowAllErrors)
            {
                Logger.Error(exc, $"Failed to execute {eventName} script.");
                Logger.Debug(script);
                var message = ResourceProvider.GetString(LOC.ErrorApplicationScript) + Environment.NewLine + exc.Message;
                if (exc is ScriptRuntimeException scriptExc)
                {
                    message = message + Environment.NewLine + Environment.NewLine + scriptExc.ScriptStackTrace;

View on GitHub (pinned to 5911f4e964)

Solutions

  1. Install/enable Windows PowerShell 5.1 (Windows optional feature) and restart Playnite.
  2. Verify HKLM\SOFTWARE\Microsoft\PowerShell\3\Install == '1'.
  3. If PowerShell cannot be installed, clear the application event script fields in Playnite settings so the code early-returns.
  4. On supported Windows, run sfc /scannow or re-add the PowerShell feature to restore the registry marker.

Example fix

// before (user config with PS absent)
// ApplicationSettings -> StartupScript contains script text -> RunAppScript throws dialog

// after — install PS or clear the script field
// Settings > Scripts > remove StartupScript content
Defensive patterns

Strategy: validation

Validate before calling

if (!PowerShellRuntime.IsInstalled)
{
    Dialogs.ShowMessage(ResourceProvider.GetString(LOC.ErrorPowerShellNotInstalled));
    return;
}
using (var runtime = new PowerShellRuntime($"app {eventName} script")) { runtime.Execute(script, ...); }

Type guard

static bool CanRunAppScript() => PowerShellRuntime.IsInstalled;

Try / catch

// RunAppScript already wraps in try/catch(!PlayniteEnvironment.ThrowAllErrors) and shows a dialog.
// To avoid the throw entirely, early-return when IsInstalled is false (it currently throws instead).

Prevention

When it happens

Trigger: RunAppScript is called for an app event whose script field is non-empty; PowerShellRuntime.IsInstalled returns false (registry marker absent), so line 849 throws before constructing a runtime.

Common situations: User on a Windows SKU without Windows PowerShell 5.1 (N edition, stripped image, Server Core without the feature) configured an application event script in Playnite settings. PowerShell was uninstalled/disabled after the script was set.

Related errors


AI-assisted analysis of JosefNemec/Playnite@5911f4e964 (2026-08-13). Data as JSON: /api/errors/0000d8b694d11dc8. Report an issue: GitHub.