Skip to content

Commit ccd57ab

Browse files
committed
fix(Windows): powershell missing modules
1 parent 36228cb commit ccd57ab

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/Everywhere.Windows/Chat/Plugins/PowerShellPlugin.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,24 @@ public PowerShellPlugin(ILogger<PowerShellPlugin> logger) : base("Shell")
1919
{
2020
_logger = logger;
2121

22-
_functions.Add(new AnonymousChatFunction(
23-
ExecutePowerShellScriptAsync,
24-
ChatFunctionPermissions.ShellExecute));
22+
// Load powershell module
23+
// from: https://github.com/PowerShell/PowerShell/issues/25793
24+
var path = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly()?.Location);
25+
#if NET9_0
26+
var modulesPath = Path.Combine(path ?? ".", "runtimes", "win", "lib", "net9.0", "Modules");
27+
#else
28+
#error Target framework not supported
29+
#endif
30+
Environment.SetEnvironmentVariable(
31+
"PSModulePath",
32+
$"{Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), @"WindowsPowerShell\v1.0\Modules")};" +
33+
$"{modulesPath};" + // Import application auto-contained modules
34+
Environment.GetEnvironmentVariable("PSModulePath"));
35+
36+
_functions.Add(
37+
new AnonymousChatFunction(
38+
ExecutePowerShellScriptAsync,
39+
ChatFunctionPermissions.ShellExecute));
2540
}
2641

2742
[KernelFunction("execute_powershell_script")]

0 commit comments

Comments
 (0)