{"record":{"id":"4133ed4f4a952eb3","repo":"JosefNemec/Playnite","slug":"powershell-5-1-is-not-installed","errorCode":null,"errorMessage":"PowerShell 5.1 is not installed.","messagePattern":"PowerShell 5\\.1 is not installed\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"source/Playnite/Scripting/PowerShell/PowerShell.cs","lineNumber":106,"sourceCode":"        private System.Management.Automation.PowerShell powershell;\r\n        private Runspace runspace;\r\n        private PSModuleInfo module;\r\n        private InitialSessionState initialSessionState;\r\n        public bool IsDisposed { get; internal set; }\r\n\r\n        public static bool IsInstalled\r\n        {\r\n            get\r\n            {\r\n                return Registry.GetValue(@\"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\PowerShell\\3\", \"Install\", null)?.ToString() == \"1\";\r\n            }\r\n        }\r\n\r\n        public PowerShellRuntime(string runspaceName)\r\n        {\r\n            if (!IsInstalled)\r\n            {\r\n                throw new Exception(\"PowerShell 5.1 is not installed.\");\r\n            }\r\n\r\n            initialSessionState = InitialSessionState.CreateDefault();\r\n            initialSessionState.ExecutionPolicy = ExecutionPolicy.Bypass;\r\n            initialSessionState.ThreadOptions = PSThreadOptions.UseCurrentThread;\r\n            powershell = System.Management.Automation.PowerShell.Create(initialSessionState);\r\n            runspace = powershell.Runspace;\r\n            runspace.Name = runspaceName;\r\n            SetVariable(\"ErrorActionPreference\", \"Stop\");\r\n            SetVariable(\"__logger\", LogManager.GetLogger(runspaceName));\r\n        }\r\n\r\n        public void Dispose()\r\n        {\r\n            IsDisposed = true;\r\n            runspace.Close();\r\n            runspace.Dispose();\r\n        }\r","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/JosefNemec/Playnite/blob/5911f4e964e628aa7a69c2030ab35101afa63067/source/Playnite/Scripting/PowerShell/PowerShell.cs#L88-L124","documentation":"Thrown by the PowerShellRuntime constructor when PowerShellRuntime.IsInstalled is false. IsInstalled checks the registry value HKLM\\SOFTWARE\\Microsoft\\PowerShell\\3\\Install == '1'; if that key/value is absent (PowerShell not registered, or only PowerShell 7+ installed), the runtime cannot be created and construction aborts.","triggerScenarios":"new PowerShellRuntime(runspaceName) is called on a machine where the Windows PowerShell 3+ registry install marker is missing. The ctor checks IsInstalled at line 104 and throws.","commonSituations":"Windows PowerShell feature disabled via 'Turn Windows features off' or stripped on Server Core / LTSC. A clean or N-edition Windows where PS 5.1 was never provisioned. User installed only PowerShell 7 (pwsh) which does not set the WindowsPowerShell\\3 key. Group policy removed the registry marker.","solutions":["Enable Windows PowerShell: Windows Settings > Apps > Optional features > add 'Windows PowerShell 2.0' and ensure Windows PowerShell 5.1 is present, or run the Windows feature: DISM /Online /Enable-Feature /FeatureName:MicrosoftWindowsPowerShell /All.","Verify the registry value exists: HKLM\\SOFTWARE\\Microsoft\\PowerShell\\3, Install = 1.","On Server Core, add the PowerShell feature via Install-WindowsFeature PowerShell.","After install, restart Playnite so IsInstalled re-reads the registry."],"exampleFix":"// guard before constructing the runtime (caller pattern already used elsewhere):\nif (!PowerShellRuntime.IsInstalled)\n{\n    // report to user / skip PowerShell-dependent feature\n    return;\n}\nusing (var runtime = new PowerShellRuntime(\"my script\")) { /* ... */ }","handlingStrategy":"validation","validationCode":"if (!PowerShellRuntime.IsInstalled)\n    throw new InvalidOperationException(\"Windows PowerShell 3+ registry marker not found; install/enable Windows PowerShell 5.1.\");\n// only then:\nusing (var runtime = new PowerShellRuntime(\"name\")) { /* ... */ }","typeGuard":"static bool CanUsePowerShell() => PowerShellRuntime.IsInstalled;","tryCatchPattern":"if (!PowerShellRuntime.IsInstalled) { /* warn user / disable PS feature */ return; }\ntry { using (var rt = new PowerShellRuntime(name)) { /* ... */ } }\ncatch (Exception ex) when (ex.Message.Contains(\"PowerShell 5.1 is not installed\")) { /* report install instructions */ }","preventionTips":["Always gate PowerShellRuntime construction on IsInstalled (the rest of the codebase already does this).","Document Windows PowerShell as a hard requirement for script-based features.","In installers/bootstrap, detect and prompt to enable the Windows feature."],"tags":["scripting","powershell","environment","windows","playnite"],"backgroundTag":null,"analyzedSha":"5911f4e964e628aa7a69c2030ab35101afa63067","analyzedAt":"2026-08-13T17:38:25.713Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}