JosefNemec/Playnite · error · Exception
PowerShell 5.1 is not installed.
Error message
PowerShell 5.1 is not installed.
What it means
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.
Source
Thrown at source/Playnite/Scripting/PowerShell/PowerShell.cs:106
private System.Management.Automation.PowerShell powershell;
private Runspace runspace;
private PSModuleInfo module;
private InitialSessionState initialSessionState;
public bool IsDisposed { get; internal set; }
public static bool IsInstalled
{
get
{
return Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3", "Install", null)?.ToString() == "1";
}
}
public PowerShellRuntime(string runspaceName)
{
if (!IsInstalled)
{
throw new Exception("PowerShell 5.1 is not installed.");
}
initialSessionState = InitialSessionState.CreateDefault();
initialSessionState.ExecutionPolicy = ExecutionPolicy.Bypass;
initialSessionState.ThreadOptions = PSThreadOptions.UseCurrentThread;
powershell = System.Management.Automation.PowerShell.Create(initialSessionState);
runspace = powershell.Runspace;
runspace.Name = runspaceName;
SetVariable("ErrorActionPreference", "Stop");
SetVariable("__logger", LogManager.GetLogger(runspaceName));
}
public void Dispose()
{
IsDisposed = true;
runspace.Close();
runspace.Dispose();
}
View on GitHub (pinned to 5911f4e964)
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.
Example fix
// guard before constructing the runtime (caller pattern already used elsewhere):
if (!PowerShellRuntime.IsInstalled)
{
// report to user / skip PowerShell-dependent feature
return;
}
using (var runtime = new PowerShellRuntime("my script")) { /* ... */ } Defensive patterns
Strategy: validation
Validate before calling
if (!PowerShellRuntime.IsInstalled)
throw new InvalidOperationException("Windows PowerShell 3+ registry marker not found; install/enable Windows PowerShell 5.1.");
// only then:
using (var runtime = new PowerShellRuntime("name")) { /* ... */ } Type guard
static bool CanUsePowerShell() => PowerShellRuntime.IsInstalled;
Try / catch
if (!PowerShellRuntime.IsInstalled) { /* warn user / disable PS feature */ return; }
try { using (var rt = new PowerShellRuntime(name)) { /* ... */ } }
catch (Exception ex) when (ex.Message.Contains("PowerShell 5.1 is not installed")) { /* report install instructions */ } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- LOC.ErrorPowerShellNotInstalled
- PowerShell 3.0 or newer is not installed.
- Cannot load script file, uknown format.
- Interactive session is already running
- e.Message
AI-assisted analysis of JosefNemec/Playnite@5911f4e964 (2026-08-13).
Data as JSON: /api/errors/4133ed4f4a952eb3.
Report an issue: GitHub.