chocolatey/choco · critical · FileNotFoundException
Unable to find suitable location for PowerShell. Searched th
Error message
Unable to find suitable location for PowerShell. Searched the following locations: '{0}' What it means
Thrown by PowershellExecutor.GetPowerShellLocation when none of the candidate PowerShell executable paths in _powershellLocations exist on the filesystem. The method iterates the known locations and, finding no match, raises a FileNotFoundException listing every location it searched.
Source
Thrown at src/chocolatey/infrastructure/commands/PowershellExecutor.cs:79
workingDirectory: fileSystem.GetDirectoryName(fileSystem.GetCurrentAssemblyPath()),
stdOutAction: stdOutAction,
stdErrAction: stdErrAction,
updateProcessPath: true,
allowUseWindow: AllowUseWindow
);
}
public static string GetPowerShellLocation(IFileSystem fileSystem)
{
foreach (var powershellLocation in _powershellLocations)
{
if (fileSystem.FileExists(powershellLocation))
{
return powershellLocation;
}
}
throw new FileNotFoundException("Unable to find suitable location for PowerShell. Searched the following locations: '{0}'".FormatWith(string.Join("; ", _powershellLocations)));
}
#pragma warning disable IDE0022, IDE1006
[Obsolete("This overload is deprecated and will be removed in v3.")]
public static int execute(
string command,
IFileSystem fileSystem,
int waitForExitSeconds,
Action<object, DataReceivedEventArgs> stdOutAction,
Action<object, DataReceivedEventArgs> stdErrAction)
=> Execute(command, fileSystem, waitForExitSeconds, stdOutAction, stdErrAction);
[Obsolete("This overload is deprecated and will be removed in v3.")]
public static string get_powershell_location(IFileSystem fileSystem)
=> GetPowerShellLocation(fileSystem);
#pragma warning restore IDE0022, IDE1006
}
}
View on GitHub (pinned to 0d5abdd10c)
Solutions
- Ensure Windows PowerShell is installed and accessible at its default System32 path (verify `where powershell` resolves).
- On PowerShell Core-only systems, confirm pwsh is on PATH at a searched location, or install it (winget install Microsoft.PowerShell).
- If running under a custom IFileSystem in tests, make sure the fake filesystem reports the expected powershell path as existing.
Example fix
// before (custom test filesystem hides powershell) var fs = new FakeFileSystem(); // FileExists always false PowershellExecutor.GetPowerShellLocation(fs); // throws // after fs.SetupFileExists(@"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe", true); PowershellExecutor.GetPowerShellLocation(fs);
Defensive patterns
Strategy: validation
Validate before calling
var known = new[]
{
@"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe",
@"C:\Program Files\PowerShell\7\pwsh.exe"
};
if (!known.Any(File.Exists))
throw new InvalidOperationException("No PowerShell installation found. Install Windows PowerShell or pwsh before running Chocolatey."); Try / catch
try
{
var ps = PowershellExecutor.GetPowerShellLocation(fileSystem);
}
catch (FileNotFoundException ex) when (ex.Message.Contains("PowerShell"))
{
logger.Error(ex.Message + " Install PowerShell (Windows PowerShell or pwsh) and retry.");
throw;
} Prevention
- Base-machine images used for Chocolatey must include PowerShell at a standard location.
- In tests using a fake IFileSystem, ensure FileExists returns true for at least one searched powershell path.
When it happens
Trigger: Any Chocolatey operation that needs to invoke PowerShell (running install/uninstall scripts, ps1 execution) on a machine where neither Windows PowerShell (powershell.exe in System32) nor PowerShell Core (pwsh) is present at the searched paths. fileSystem.FileExists returns false for all entries in _powershellLocations.
Common situations: Hardened/Server Core images where PowerShell was intentionally removed, locked-down environments where System32 access is restricted, or a tampered/redirected filesystem abstraction in tests that hides the real binaries.
Related errors
- The environment variable scope value '{scope}' is not suppor
- No {0} files (or more than 1) were found to build in '{1}'.
- Could not find a file in the manifest resource stream of '{0
- Unable to load licensed assembly.
AI-assisted analysis of chocolatey/choco@0d5abdd10c (2026-08-13).
Data as JSON: /api/errors/45fe47e9d4bd1485.
Report an issue: GitHub.