{"record":{"id":"0000d8b694d11dc8","repo":"JosefNemec/Playnite","slug":"loc-errorpowershellnotinstalled","errorCode":null,"errorMessage":"LOC.ErrorPowerShellNotInstalled","messagePattern":"LOC\\.ErrorPowerShellNotInstalled","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"source/Playnite/ViewModels/MainViewModelBase.cs","lineNumber":849,"sourceCode":"            await GlobalTaskHandler.CancelAndWaitAsync();\r\n        }\r\n\r\n        public virtual void SelectGame(Guid id, bool restoreView = false)\r\n        {\r\n        }\r\n\r\n        private void RunAppScript(string script, string eventName)\r\n        {\r\n            if (script.IsNullOrWhiteSpace())\r\n            {\r\n                return;\r\n            }\r\n\r\n            try\r\n            {\r\n                if (!PowerShellRuntime.IsInstalled)\r\n                {\r\n                    throw new Exception(ResourceProvider.GetString(LOC.ErrorPowerShellNotInstalled));\r\n                }\r\n\r\n                using (var runtime = new PowerShellRuntime($\"app {eventName} script\"))\r\n                {\r\n                    runtime.Execute(\r\n                        script,\r\n                        PlaynitePaths.ProgramPath,\r\n                        new Dictionary<string, object> { { \"PlayniteApi\", App.PlayniteApiGlobal } });\r\n                }\r\n            }\r\n            catch (Exception exc) when (!PlayniteEnvironment.ThrowAllErrors)\r\n            {\r\n                Logger.Error(exc, $\"Failed to execute {eventName} script.\");\r\n                Logger.Debug(script);\r\n                var message = ResourceProvider.GetString(LOC.ErrorApplicationScript) + Environment.NewLine + exc.Message;\r\n                if (exc is ScriptRuntimeException scriptExc)\r\n                {\r\n                    message = message + Environment.NewLine + Environment.NewLine + scriptExc.ScriptStackTrace;\r","sourceCodeStart":831,"sourceCodeEnd":867,"githubUrl":"https://github.com/JosefNemec/Playnite/blob/5911f4e964e628aa7a69c2030ab35101afa63067/source/Playnite/ViewModels/MainViewModelBase.cs#L831-L867","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Install/enable Windows PowerShell 5.1 (Windows optional feature) and restart Playnite.","Verify HKLM\\SOFTWARE\\Microsoft\\PowerShell\\3\\Install == '1'.","If PowerShell cannot be installed, clear the application event script fields in Playnite settings so the code early-returns.","On supported Windows, run sfc /scannow or re-add the PowerShell feature to restore the registry marker."],"exampleFix":"// before (user config with PS absent)\n// ApplicationSettings -> StartupScript contains script text -> RunAppScript throws dialog\n\n// after — install PS or clear the script field\n// Settings > Scripts > remove StartupScript content","handlingStrategy":"validation","validationCode":"if (!PowerShellRuntime.IsInstalled)\n{\n    Dialogs.ShowMessage(ResourceProvider.GetString(LOC.ErrorPowerShellNotInstalled));\n    return;\n}\nusing (var runtime = new PowerShellRuntime($\"app {eventName} script\")) { runtime.Execute(script, ...); }","typeGuard":"static bool CanRunAppScript() => PowerShellRuntime.IsInstalled;","tryCatchPattern":"// RunAppScript already wraps in try/catch(!PlayniteEnvironment.ThrowAllErrors) and shows a dialog.\n// To avoid the throw entirely, early-return when IsInstalled is false (it currently throws instead).","preventionTips":["Detect PowerShell availability at app startup and disable script-driven features if absent.","Surface install instructions when the user configures a script on a machine without PS.","Clear script settings if PS is later uninstalled."],"tags":["scripting","powershell","environment","application","playnite"],"backgroundTag":null,"analyzedSha":"5911f4e964e628aa7a69c2030ab35101afa63067","analyzedAt":"2026-08-13T17:38:25.713Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}