{"record":{"id":"45fe47e9d4bd1485","repo":"chocolatey/choco","slug":"unable-to-find-suitable-location-for-powershell-s","errorCode":null,"errorMessage":"Unable to find suitable location for PowerShell. Searched the following locations: '{0}'","messagePattern":"Unable to find suitable location for PowerShell\\. Searched the following locations: '(.+?)'","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"critical","filePath":"src/chocolatey/infrastructure/commands/PowershellExecutor.cs","lineNumber":79,"sourceCode":"                workingDirectory: fileSystem.GetDirectoryName(fileSystem.GetCurrentAssemblyPath()),\r\n                stdOutAction: stdOutAction,\r\n                stdErrAction: stdErrAction,\r\n                updateProcessPath: true,\r\n                allowUseWindow: AllowUseWindow\r\n                );\r\n        }\r\n\r\n        public static string GetPowerShellLocation(IFileSystem fileSystem)\r\n        {\r\n            foreach (var powershellLocation in _powershellLocations)\r\n            {\r\n                if (fileSystem.FileExists(powershellLocation))\r\n                {\r\n                    return powershellLocation;\r\n                }\r\n            }\r\n\r\n            throw new FileNotFoundException(\"Unable to find suitable location for PowerShell. Searched the following locations: '{0}'\".FormatWith(string.Join(\"; \", _powershellLocations)));\r\n        }\r\n\r\n#pragma warning disable IDE0022, IDE1006\r\n        [Obsolete(\"This overload is deprecated and will be removed in v3.\")]\r\n        public static int execute(\r\n            string command,\r\n            IFileSystem fileSystem,\r\n            int waitForExitSeconds,\r\n            Action<object, DataReceivedEventArgs> stdOutAction,\r\n            Action<object, DataReceivedEventArgs> stdErrAction)\r\n            => Execute(command, fileSystem, waitForExitSeconds, stdOutAction, stdErrAction);\r\n\r\n        [Obsolete(\"This overload is deprecated and will be removed in v3.\")]\r\n        public static string get_powershell_location(IFileSystem fileSystem)\r\n            => GetPowerShellLocation(fileSystem);\r\n#pragma warning restore IDE0022, IDE1006\r\n    }\r\n}\r","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/chocolatey/choco/blob/0d5abdd10cc177a141e69547cad6935b419b6c17/src/chocolatey/infrastructure/commands/PowershellExecutor.cs#L61-L97","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (custom test filesystem hides powershell)\nvar fs = new FakeFileSystem(); // FileExists always false\nPowershellExecutor.GetPowerShellLocation(fs); // throws\n\n// after\nfs.SetupFileExists(@\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\", true);\nPowershellExecutor.GetPowerShellLocation(fs);","handlingStrategy":"validation","validationCode":"var known = new[]\n{\n    @\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\",\n    @\"C:\\Program Files\\PowerShell\\7\\pwsh.exe\"\n};\nif (!known.Any(File.Exists))\n    throw new InvalidOperationException(\"No PowerShell installation found. Install Windows PowerShell or pwsh before running Chocolatey.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    var ps = PowershellExecutor.GetPowerShellLocation(fileSystem);\n}\ncatch (FileNotFoundException ex) when (ex.Message.Contains(\"PowerShell\"))\n{\n    logger.Error(ex.Message + \" Install PowerShell (Windows PowerShell or pwsh) and retry.\");\n    throw;\n}","preventionTips":["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."],"tags":["powershell","runtime-dependency","filenotfound","environment"],"backgroundTag":null,"analyzedSha":"0d5abdd10cc177a141e69547cad6935b419b6c17","analyzedAt":"2026-08-13T18:33:03.301Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}